1//indexOf - JS method to get index of array element.
2// Returns -1 if not found
3
4var colors=["red","green","blue"];
5var pos=colors.indexOf("blue");//2
6
7//indexOf getting index of sub string, returns -1 if not found
8
9var str = "We got a poop cleanup on isle 4.";
10var strPos = str.indexOf("poop");//9
11
12//Eg with material ui
13
14<Checkbox
15 checked={value.indexOf(option) > -1}
16 value={option}
17/>
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