0

I have an array of arrays aa = [[value, value2], [value3, value4]] and I need to check if my new array a = [value2, value7] includes any value from aa I had tried this code and then i tried with adding .every to the aa but doesnt work. what should i do

a.some(r=> aa.includes(r))

a.some(r=> aa.every.includes(r))
1
  • a.some(value => aa.some(inner => inner.includes(value)) Commented Apr 3, 2020 at 23:08

1 Answer 1

1

Since you are using a nested array, you will want to use Array.prototype.flat on the aa array first. This will convert:

[[value, value2], [value3, value4]]

...to:

[value, value2, value3, value4]

See proof-of-concept below:

const aa = [[1, 2], [3, 4]];
const a = [2, 7];

// Flatten nested arrays
const aaFlat = aa.flat();

console.log(a.some(x => aaFlat.includes(x)));

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.