Answers for "8.3.1. Common Array Methods // indexOf Examples (.indexOf)"

0

8.3.1. Common Array Methods // indexOf Examples (.indexOf)

//The general syntax for this method is:
arrayName.indexOf(item)

/*This method returns the index of the FIRST occurence of an item in
the array. If the item is not in the array, -1 is returned.*/

let charles = [1, 7, 5, 9, 5];
let otherArray = ['hello', 'world!'];

console.log(charles.indexOf(5));

console.log(otherArray.indexOf('hi'));

//2
//-1
Posted by: Guest on June-14-2021

Code answers related to "8.3.1. Common Array Methods // indexOf Examples (.indexOf)"

Code answers related to "Javascript"

Browse Popular Code Answers by Language