javascript remove null from array

Posted by Paidboom - 5 months ago

Write a JavaScript function to remove null, 0, blank, false, undefined and NaN values from an array.

Remove empty elements from an array in Javascript

let array = [0, 1, null, 2, 3];

function removeNull(array) {
return array.filter(x => x !== null)

Javascript remove empty elements from array

var colors=["red","blue",,null,undefined,,"green"];

var realColors = colors.filter(function (e) {return e != null;});

//remove null and undefined elements from colors

arr = [nil, "say", "kenglish", "co", nil]
# returns new array with ["say", "kenglish", "co"