Manju Kb Manju Kb - 1 month ago 8
Javascript Question

How javascripts indexOfKey works

I have an array object like this

var x = [{"_id":null,"count":7},{"_id":false,"count":362}, {"_id":true,"count":926}]

How to take index of _id = false; object

tried this
x.indexOfKey(false, "_id")
but returns -1
and this works fine
x.indexOfKey(true, "_id")

What am i doing wrong??


Use the standard array.findIndex API.


var x =  [{"_id":null,"count":7},{"_id":false,"count":362}, {"_id":true,"count":926}];
console.log("Index of _id==false is: " + x.findIndex((element) => { return element._id == false; }));