Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Falsy Bouncer

// Falsy Bouncer
// Remove all falsy values from an array.
// Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
// Hint: Try converting each value to a Boolean.

function bouncer(arr) {
	let newArray = [];
	for (let i = 0; i < arr.length; i++) {
		if (arr[i]) newArray.push(arr[i]);
	}
	return newArray;
}

// OR

function bouncer(arr) {
	return arr.filter(Boolean);
}

bouncer([7, 'ate', '', false, 9]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: focus on child components on single page applications - 1 
Javascript :: empty donut chart chart js 
Javascript :: Reactjs class exemple componentDidMount 
Javascript :: jquery excel export 
Javascript :: jquery get selected checkbox items and pass to parameter for C# MVC consumption 
Javascript :: Setting, getting, and removing data attributes vanilla javascript 
Javascript :: mongoose operand find method 
Javascript :: how can i use two api at the same time in angular 
Javascript :: requiere and get a property simplified with Node 
Javascript :: connect to local mongodb node 
Javascript :: Cache and return requests 
Javascript :: Play Gif or Video On hover Jquery 
Javascript :: how to replace multiple characters in url in jqury 
Javascript :: template.json exlude files from generating 
Javascript :: escape exponential input number in js 
Javascript :: Google Maps JavaScript API warning: InvalidKey https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key 
Javascript :: speed of sound 
Javascript :: JSON stringify method - the optional parameters 
Javascript :: cercle progress bar angular 
Javascript :: minutes to seconds javascript 
Javascript :: simple method 
Javascript :: error 28 mongodb 
Javascript :: jquery datatable dropdown from stored procedure values 
Javascript :: pass data from popup js 
Javascript :: automatic color change 
Javascript :: js set array relation 
Javascript :: eslint failed to load react 
Javascript :: Allowed Blocks in Nested Blocks Component Wordpress 
Javascript :: material ui table row onclick 
Javascript :: .pop get second element of url 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =