I have a array and this array's elements is a array;
var array = [
[0,1],
[0,2],
[0,3],
[0,0]
];
But when i use array.indexOf([0,1]); it return -1.
I have a array and this array's elements is a array;
var array = [
[0,1],
[0,2],
[0,3],
[0,0]
];
But when i use array.indexOf([0,1]); it return -1.
You can use Array#findIndex
with your own implementation of equality comparison.
var array = [
[0,1],
[0,2],
[0,3],
[0,0]
];
function equals(arr1, arr2){
return arr1.length === arr2.length && arr1.every((x, i)=>x === arr2[i]);
}
let target = [0, 2];
let idx = array.findIndex(x => equals(x, target));
console.log(idx);