Find the index of a particular element in groceryList using .indexOf().

PHOTO EMBED

Fri Oct 01 2021 11:46:59 GMT+0000 (Coordinated Universal Time)

Saved by @ianvalentino #javascript #method

const groceryList = ['orange juice', 'bananas', 'coffee beans', 'brown rice', 'pasta', 'coconut oil', 'plantains'];

const pastaIndex = groceryList.indexOf('pasta');

console.log(pastaIndex);
content_copyCOPY

Call .indexOf() on groceryList to find the index of the element 'pasta' and save the returned value to a const variable named pastaIndex. Then log pastaIndex to the console. (You may remove the other console.log() statements to declutter the terminal.) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

https://www.codecademy.com/courses/introduction-to-javascript/lessons/arrays/exercises/more-array-methods