js indexof

JavaScript
//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");//9var indices = [];
var array = ['a', 'b', 'a', 'c', 'a', 'd'];
var element = 'a';
var idx = array.indexOf(element);
while (idx != -1) {
  indices.push(idx);
  idx = array.indexOf(element, idx + 1);
}
console.log(indices);
// [0, 2, 4]
//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}
/>const paragraph = 'The quick brown fox';

console.log(paragraph.indexOf('T'));
>> 0

console.log(paragraph.indexOf('h'));
>> 1

console.log(paragraph.indexOf('Th'));
>> 0

console.log(paragraph.indexOf('he'));
>> 1

console.log(paragraph.indexOf('x'));
>> 18var fruits = ["Banana", "Orange", "Apple", "Mango"];
return fruits.indexOf("Apple"); // Returns 2/"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
Source

Also in JavaScript: