Returns the index of the element, or -1 if not found
let array = [1,2,3,4,5]; let index = array.indexOf(2); console.log(index); // 1 array = ['cat', 'dog', 'pig']; index = array.indexOf('pig'); console.log(index); // 2
Last updated 3 years ago
Was this helpful?