Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array filter falsy values

const numbersWithFalsyValues = [7, null, 10, 17, false, NaN];
const numbers = numbersWithFalsyValues.filter(Boolean);
console.log(numbers); //[7,10,17]

const namesWithFalsyValues=["Raj", "", "Joy", undefined, false];
const names = namesWithFalsyValues.filter(Boolean);
console.log(names); //['Raj','Joy']

const mixDataWithFalsyValues = [2, 0, "", "Joy", null, undefined, false];
const mixData = mixDataWithFalsyValues.filter(Boolean);
console.log(mixData); //[2,'Joy']
 
PREVIOUS NEXT
Tagged: #array #filter #falsy #values
ADD COMMENT
Topic
Name
1+4 =