1//indexOf getting index of array element, returns -1 if not found
2var colors=["red","green","blue"];
3var pos=colors.indexOf("blue");//2
4
5//indexOf getting index of sub string, returns -1 if not found
6var str = "We got a poop cleanup on isle 4.";
7var strPos = str.indexOf("poop");//9
1let monTableau = ['un', 'deux','trois', 'quatre'] ;
2console.log(monTableau.indexOf('trois')) ;
3
1const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
2
3const searchTerm = 'dog';
4const indexOfFirst = paragraph.indexOf(searchTerm);
5
6console.log(`The index of the first "${searchTerm}" from the beginning is ${indexOfFirst}`);
7// expected output: "The index of the first "dog" from the beginning is 40"
8
9console.log(`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchTerm, (indexOfFirst + 1))}`);
10// expected output: "The index of the 2nd "dog" is 52"
11