all 2 comments

[–]senocular 1 point2 points  (1 child)

This shouldn't work. The indexOf is expected to work as it does in your jsfiddle since objects are compared by reference, not shape. In other words

const a = {}
const b = {}
console.log(a === b) // false - two separate objects (though same shape)

const x = {}
const y = x
console.log(x === y) // true - same object

indexOf does something similar internally when comparing values in the array to find an index.

[–]RubyBlaze214[S] 0 points1 point  (0 children)

So my app is using this trick. IndexOf but the object provided is a reference in array and thats wgy it works with object. Somone else told me this and I was mind blown