Lisa
0
Q:

indexof()

//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
30
//indexOf - JS method to get index of array element. 
// Returns -1 if not found

var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found

var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9

//Eg with material ui

<Checkbox
   checked={value.indexOf(option) > -1}
   value={option}
/>
14
/"returns the index, of that element, or -1 if the element does not exist."/

let fruits = ['apples', 'pears', 'oranges', 'peaches', 'pears'];

fruits.indexOf('dates'); // returns -1
fruits.indexOf('oranges'); // returns 2
fruits.indexOf('pears'); // returns 1, first index at which the element exists
4

fruits = ['apple', 'banana', 'cherry']
print(fruits.index("cherry"))
#--> 2
4

var str = "Hello world, welcome to the universe.";

var n = str.indexOf("welcome");
 
0
Array.indexOf(searchElement, fromIndex)
10
let monTableau = ['un', 'deux','trois', 'quatre'] ;
console.log(monTableau.indexOf('trois')) ;
 
2
var resultArr = indexArr.map(i => fruitier[i])
0
String1.indexOf(index2); 
0

New to Communities?

Join the community