indexof object code example

Example 1: using index of on array of objects

arr = [{x: "a", y: 1}, {x: "something", y: 2}]
arr.findIndex(obj => obj.x === "a" && obj.y === 1);

Example 2: indexOf by object key

var index = peoples.findIndex(p => p.attr1 == "john")

Example 3: javasript array indexof

var array = [2, 9, 9];
array.indexOf(2);     // 0
array.indexOf(7);     // -1
array.indexOf(9, 2);  // 2
array.indexOf(2, -1); // -1
array.indexOf(2, -3); // 0

Example 4: indexof object javascript

var hello = {
    hello: 'world',
    foo: 'bar'
};
var qaz = {
    hello: 'stevie',
    foo: 'baz'
}

var myArray = [];
myArray.push(hello,qaz);

var indexOfStevie = myArray.findIndex(i => i.hello === "stevie");

Example 5: indexof

String1.indexOf(index2);

Example 6: indexof javascript

arr.indexOf(searchElement[, fromIndex])