javascript string findindex code example
Example 1: javascript findindex
const array1 = [5, 12, 8, 130, 44];
const search = element => element > 13;
console.log(array1.findIndex(search));
const array2 = [
{ id: 1, dev: false },
{ id: 2, dev: false },
{ id: 3, dev: true }
];
const search = obj => obj.dev === true;
console.log(array2.findIndex(search));
Example 2: 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 3: findindex js
const array = [5, 12, 8, 130, 44];
const index = array.findIndex((item)=> item>10);
console.log(array[index]);
Example 4: js indexof string
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'));
>> 18
Example 5: 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 6: js indexof string
str.indexOf(searchValue[, fromIndex])