Let's discuss a scenario where I have to decide whether to display a block based on a certain condition.
Here is an example array structure:
const data = [
{ name: "item1" , values : [0,0,0,0,0]},
{ name: "item2" , values : [0,0,0,0,0]},
{ name: "item3" , values : [0,0,0,0,0]}
] // should return false
const data = [
{ name: "item1" , values : [0,0,0,0,0]},
{ name: "item2" , values : [0,1,0,0,0]},
{ name: "item3" , values : [0,0,0,0,0]}
] // should return true
The condition I need to check is that if all values inside the "values" array of each object are 0, then return false. If any value inside the "values" array is not 0, return true.
I attempted the following code, but it doesn't seem to work as expected:
const isZero = (currentValue) => currentValue === 0;
console.log(data.every(isZero));