let answer = []; let arrA = [[1, 4], [3, 4], [3, 10]] let arrB = [[ 1, 4 ], [1, 10], [ 3, 4], [3, 10]]
the results of arrA.indexOf(arrB [i]) == -1
turn out to be false for all.
How can I solve it?
let answer = []; let arrA = [[1, 4], [3, 4], [3, 10]] let arrB = [[ 1, 4 ], [1, 10], [ 3, 4], [3, 10]]
the results of arrA.indexOf(arrB [i]) == -1
turn out to be false for all.
How can I solve it?
You can use findIndex
let answer = [];
let arrA = [
[1, 4],
[3, 4],
[3, 10]
]
let arrB = [
[1, 4],
[1, 10],
[3, 4],
[3, 10]
]
for (const a of arrB) {
const index = arrA.findIndex(o => o[0] === a[0] && o[1] === a[1])
answer.push(index)
}
console.log(answer)