TIL checking falsy values inside an array
POSTED ON:
TAGS: array javascript
// has falsy values
const theArray = [false, null, 0, 'wizard', undefined, 'barbarian'];
// return true/false if a truthy value exists
const ifAnyIsTrue = theArray.some(Boolean); // true
// return true/false if ALL truthy value exists
const ifAllAreTrue = theArray.every(Boolean); // false
// returns the true values
const giveMeTrueValues = theArray.filter(Boolean);
Related TILs
Tagged: array