1const a = [3,,null, false, undefined, 1];
2
3// Remove falsey
4a.filter(Boolean);
5
6// Remove specific (undefined)
7a.filter(e => e !== undefined);
1let array = [0, 1, null, 2, 3];
2
3function removeNull(array) {
4return array.filter(x => x !== null)
5};
1var data = [42, 21, undefined, 50, 40, undefined, 9];
2
3data = data.filter(function( element ) {
4 return element !== undefined;
5});
1// ES6+
2const arr = [1, undefined, 2, 3, undefined, 5];
3
4const filteredArr = arr.filter((elem) => elem !== undefined);
5
6console.log(filteredArr); // output: [1, 2, 3, 5]
1var colors=["red","blue",,null,undefined,,"green"];
2
3//remove null and undefined elements from colors
4var realColors = colors.filter(function (e) {return e != null;});
5console.log(realColors);
1var array = [0, 1, null, 2, "", 3, undefined, 3,,,,,, 4,, 4,, 5,, 6,,,,];
2
3var filtered = array.filter(function (el) {
4 return el != null;
5});
6
7console.log(filtered);