EN
JavaScript - check if all values in array are falsy
0 points
In this article, we would like to show you how to check if all values in the array are falsy in JavaScript.
In this example, we use every()
method to check if all values in the array are falsy.
xxxxxxxxxx
1
const falsyCheck = (array) => array.every((element) => !element);
2
3
4
// Usage example
5
6
const falsyValues = [false, 0, -0, 0n, '', '', ``, null, undefined, NaN];
7
8
console.log(falsyCheck(falsyValues)); // true
Note:
The
every()
method returnstrue
only when all elements in thearray
pass the test implemented by the provided function (when all negated elements are truthy).