Manju Kb Manju Kb - 1 year ago 98
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??

Answer Source

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; }));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download