Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js filter undefined from array

var arr = [1,2,,3,,-3,null,,0,,undefined,4,,4,,5,,6,,,,];


arr.filter(n => n)
// [1, 2, 3, -3, 4, 4, 5, 6]

arr.filter(Number) 
// [1, 2, 3, -3, 4, 4, 5, 6]

arr.filter(Boolean) 
// [1, 2, 3, -3, 4, 4, 5, 6]
Comment

PREVIOUS NEXT
Code Example
Javascript :: compare and filter two array of object 
Javascript :: connecting react to socket.io 
Javascript :: sum of n numbers in javascript 
Javascript :: how to append rows in table using jquery each function 
Javascript :: remove first and last character javascript 
Javascript :: string replace in javascript 
Javascript :: encrypt data using SHA256 algorithm in JavaScript 
Javascript :: ajax datatable reload paging retained 
Javascript :: trigger click on checkbox jquery 
Javascript :: pymongo add json to collection 
Javascript :: javascript rotate image canvas 
Javascript :: sum numbers recursively js 
Javascript :: encodeuri hashtag 
Javascript :: redux append to an array 
Javascript :: fetch patch method 
Javascript :: content editable vuejs 
Javascript :: how create an index mongodb 
Javascript :: speedtest-net node.js 
Javascript :: how to check checked checkbox in jquery 
Javascript :: get data from url javascript 
Javascript :: cache remove using ajax 
Javascript :: fetch data flutter json 
Javascript :: javascript parse json 
Javascript :: dropdown option selection change event in jquery 
Javascript :: collection to array javascript 
Javascript :: vue on click router push not working 
Javascript :: how to clear local storage 
Javascript :: javascript hard reload 
Javascript :: How to calc() height in react native for styling 
Javascript :: require is not defined on html script with electron 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =