Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter falsy values js

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: #filter #falsy #values #js
ADD COMMENT
Topic
Name
1+7 =