Finding Elements in Arrays in Javascript


Use .indexOf() to find the index of an element in an array.

Source Code

let fruits = ['apple', 'banana', 'cherry'];
let index = fruits.indexOf('banana');
console.log(index); // 1
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments