0

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?

user2342558
  • 5,567
  • 5
  • 33
  • 54
  • not sure what you are trying to do – cmgchess May 12 '23 at 07:48
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=javascript+2D+array+indexOf+site%3Astackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan May 12 '23 at 07:54

1 Answers1

0

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)
Konrad
  • 21,590
  • 4
  • 28
  • 64