Can’t get why this works this way?
To which type js converts item with value = 0 and why ?
if([1,2,0,1].find(item => item === 0)) {
console.log(1); // logs nothing
}
console.log(0 === 0); // logs true
>Solution :
find returns the element it found, and 0 is falsy so if(0) never runs the conditional block.
You should use if (arr.includes(0)). Alternatives that would also work, but are more ugly, are
if (arr.some(item => item === 0))if (arr.findIndex(item => item === 0) > -1)if (arr.find(item => item === 0) !== undefined)