I have an array of objects. I am attempting to locate the index of an object inside this array, however it always returns -1 unless I "cheat". I cannot see the difference here and it console.logs the exact same output both ways. It only works one way... Is this a bug?
var arr = [{ un: 'test', uid: 1 }];
console.log("array",arr,typeof arr);
var obj = { un: 'test', uid: 1};
console.log("obj",obj);
console.log(arr[0],typeof arr[0]);
console.log("indexOf",arr.indexOf(obj));
arr.push(obj);
console.log(arr);
console.log("indexOf",arr.indexOf(obj));
The Output is this:
array [ { un: 'test', uid: 1 } ] object
obj { un: 'test', uid: 1 }
{ un: 'test', uid: 1 } 'object'
indexOf -1
[ { un: 'test', uid: 1 }, { un: 'test', uid: 1 } ]
indexOf 1
For the life of me, I cannot see the difference here. Am I missing something simple here? It's possible... considering the hours of coding, simple things get overlooked.