Q:

Get the value of one array according to another arrays index

I'm trying to get the value of the numierical value inside array1 by using the index of array2. So for instance my arrays look like this:
const array1 = ["3","4","5","6","7","8"];
const array2 = ["bat","cat","dog","fish","cow","bird"];

If the user selects "cat", it should grab "4".
array2.forEach(animal => {
   console.log(array1.indexOf(animal)); // returns -1 
});

How can I make this work?

A:

Pass the current index of array2 into the forEach callback (second argument)

const array1 = ["3","4","5","6","7","8"];
const array2 = ["bat","cat","dog","fish","cow","bird"];

array2.forEach((animal, i) => {
   console.log(array1[i]);
});

A:

Just use bracket notation and indexOf

const array1 = ["3","4","5","6","7","8"];
const array2 = ["bat","cat","dog","fish","cow","bird"];

let choice = 'cat'; // user selection

let result = array1[array2.indexOf(choice)]; // grab value

alert(result);

