javascript indexof function code example
Example 1: javascript indexof
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");
Example 2: make indexOF in js
function indexOf(arr, value) {
for (let [i, e] of arr.entries()) {
if (value == e) return i;
}
return -1;
}
indexOf([1,2,3], 2);
Example 3: js indexof string
str.indexOf(searchValue[, fromIndex])
Example 4: indexof javascript
Array.indexOf(searchElement, fromIndex)