I have simple nested array, like:
var arr = [[75.0], [65.0]] ;
and when I do:
arr.indexOf( [75.0] );
I expect 0, but I get -1, what gives?
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf :
indexOf() compares searchElement to elements of the Array using strict equality (the same method used by the === or triple-equals operator).
There is the problem. In your example, you have an array of arrays. Comparing with === operator means that for it to evaluate to true, it has to be the same array object. Clearly it is a different object so it is not found from the array.
You need to use Array.find() instead where you can provide the testing function. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
[1] == [1]. It's for the same reason.indexOfuses an===match to see if what you provide matches what's in the array. No two separate arrays are===to each other ([75.0] === [75.0]isfalse), even if the arrays have the same contents. To find the index of an equivalent array, you'll need to usefindIndexand provide a callback that checks that the arrays have the same contents, for instance (assumigntargetis the array to find):const index = arr.findIndex(entry => entry.length === target.length && entry.every((value, index) => value === target[index]));.findindexpolyfill:var index = arr.findIndex(function(entry) { return entry.length === target.length && entry.every(function(value, index) { return value === target[index]; }); });).