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)?
You would have to compare the properties. Something like this would work: