I need to get the index of the json object in an array whose by the objects id
here is the example code
var list = [ { _id: \'4dd822c5e8a6c42aa7000
function index_of(haystack, needle) { for (var i = 0, l = haystack.length; i < l; ++i) { if( haystack[i]._id === needle ) { return i; } } return -1; } console.log(index_of(list, '4dd80b16e8a6c428a900007d'));
same as the above, but caches the length of the haystack.