I am trying to find if an array of arrays includes a value. Is it possible to do this without a for loop?
The below always returns false.
const testArr = [
[0,0,0],
[0,1,0],
[0,3,0]
]
console.log(testArr.includes(3))
I am trying to find if an array of arrays includes a value. Is it possible to do this without a for loop?
The below always returns false.
const testArr = [
[0,0,0],
[0,1,0],
[0,3,0]
]
console.log(testArr.includes(3))
You have to handle each level of arrays separately, whether that is by looping or by using array functions.
testArr.some(subArr => subArr.includes(3));
This will return true if one or more of the sub arrays include 3.
testArr.reduce((a,b)=>{return [...a,...b]}).includes(3)