Search
 
SCRIPT & CODE EXAMPLE
 

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

filter the falsy values out of an array in a very simple way!

var arr = [ 0, 1, '', undefined, false, 2, undefined, null, , 3, NaN ];
 
var filtered = arr.filter(Boolean);
console.log(filtered);
 
/*
    Output: [ 1, 2, 3 ]
*/
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add another schema id on mongodb 
Javascript :: longest word javascript 
Javascript :: html add new line in js alert 
Javascript :: javascript thousand separator 
Javascript :: react native apk build 
Javascript :: how to create a button with react 
Javascript :: javascript compare two objects 
Javascript :: javascript new date 30 days ago 
Javascript :: regex pattern to validate email 
Javascript :: vuex v-model 
Javascript :: get nearby store by latitude and longitude from my latitude and long node js 
Javascript :: express search query template 
Javascript :: type of variable js 
Javascript :: what is global execution context in javascript 
Javascript :: js omit last string 
Javascript :: asp.net core 3.1 convert system.string[] to javascript 
Javascript :: Javascript file in html angeben 
Javascript :: calling javascript functions from unity scripts 
Javascript :: imagebackground in react native 
Javascript :: compare dates in js 
Javascript :: node js get input from console 
Javascript :: string contains in javascript 
Javascript :: remove duplicates from array of objects javascript 
Javascript :: how to return 5 records instead of 10 records in datatable in laravel 
Javascript :: how to use sweet alert in vue js 
Javascript :: ascending and descending val in array using js 
Javascript :: chartjs how to disable hover lable 
Javascript :: how to capitalize a letter based on an index in javascript 
Javascript :: how to make stairs in javascript 
Javascript :: ciclo for javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =