Removing all the empty elements like null,0,'',"",undefined using function
We use this method, extending the native Array prototype:
Or we can simply push the existing elements into other array:
If we need to remove ALL empty values ("", null, undefined and 0):
To remove empty values and Line breaks:
In some situations we may want to keep "0" in the array and remove anything else (null, undefined and ""), this is one way:
Here we can do this,
or using underscorejs.org :
return true callback function, e.g.:
.filter automatically skips missing elements in the original array.
- The MDN page linked above also contains a nice error-checking version of
- Note that this will not remove
null entries nor entries with an explicit
undefined value, but the OP specifically requested "missing" entries.
The clean way to do it.