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?

1
  • not sure what you are trying to do Commented May 12, 2023 at 7:48

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, but to make my answer correct, ` if(index== -1){ answer= a; }` this code worked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.