Reputation: 305
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))
Upvotes: 0
Views: 26
Reputation: 66228
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)));
Upvotes: 1