I want to use indexOf() on an array of objects. For example:
var arr;
var arr[0] = {a: 1, b: 2};
var arr[1] = {a: 1, b: 3};
var obj = {a: 1, b: 2};
console.log(arr.indexOf(obj));
This will print -1 because arr[0] does not equal obj. How can I make this work (i.e., print 0)?
I created a
similarfunction which compares almost anything, a while back:Of course
similarcan be made to find thesimilarIndexof aneedle(anything) in anhaystack(array of anything), like so: