Search
 
SCRIPT & CODE EXAMPLE
 

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']
Comment

PREVIOUS NEXT
Code Example
Javascript :: meteor update package 
Javascript :: javascript scroll event 
Javascript :: array unique values javascript 
Javascript :: number format in javascript 
Javascript :: disable input field using jquery 
Javascript :: javascript add element next to another 
Javascript :: alias import javascript 
Javascript :: Jquery search in json 
Javascript :: class constructor 
Javascript :: Vanilla JS (on)load with page 
Javascript :: javascript show localstorage size 
Javascript :: noise margin in digital electronics 
Javascript :: js check if obj all false 
Javascript :: string length jquery 
Javascript :: js create timestamp with 10 digits 
Javascript :: jquery get textarea text 
Javascript :: remove first char javascript 
Javascript :: vue select option get attribute 
Javascript :: js cypress div text 
Javascript :: javascript loop through array of objects 
Javascript :: javascript split string into array by comma and space 
Javascript :: string contains javascirpt 
Javascript :: update angular to specific version 
Javascript :: nodejs recursively read directory 
Javascript :: javascript use camera 
Javascript :: jquery on load 
Javascript :: open a html file using js 
Javascript :: loop key in object 
Javascript :: back button next js 
Javascript :: js fetch send json 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =