8 3 1 common array methods 2f 2f indexof examples 28 indexof 29

Solutions on MaxInterview for 8 3 1 common array methods 2f 2f indexof examples 28 indexof 29 by the best coders in the world

showing results for - "8 3 1 common array methods 2f 2f indexof examples 28 indexof 29"
Samuel
08 Aug 2017
1//The general syntax for this method is:
2arrayName.indexOf(item)
3
4/*This method returns the index of the FIRST occurence of an item in
5the array. If the item is not in the array, -1 is returned.*/
6
7let charles = [1, 7, 5, 9, 5];
8let otherArray = ['hello', 'world!'];
9
10console.log(charles.indexOf(5));
11
12console.log(otherArray.indexOf('hi'));
13
14//2
15//-1
similar questions