const a = [3,,null, false, undefined, 1];
// Remove falsey
a.filter(Boolean);
// Remove specific (undefined)
a.filter(e => e !== undefined);
var data = [42, 21, undefined, 50, 40, undefined, 9];
data = data.filter(function( element ) {
return element !== undefined;
});
// ES6+
const arr = [1, undefined, 2, 3, undefined, 5];
const filteredArr = arr.filter((elem) => elem !== undefined);
console.log(filteredArr); // output: [1, 2, 3, 5]
data.filter(e => e)
const a = [3,,null, false, undefined, 1];
// Remove falsey
a.filter(Boolean);