javascript
Remove all false, null, undefined and empty values from array using Lodash
To remove all falsey values like - false, null, 0, "", undefined and NaN, you can use lodash _.compact() method.
const arr = [5, 'one', 0, 1, false, 2, NaN, '', 3, undefined];
const new_arr = _.compact(arr)
The _.compact() method takes the array as parameter and return new array that does not contains falsey values.
Live Demo
Was this helpful?
Similar Posts
- Remove empty, false, undefined values from array Javscript
- Check if a variable is null, empty, undefined or false Javascript
- Javascript code to remove falsy value like null, undefined, false from array
- Get all values from an array which does not exist in other array Lodash
- Remove items starting from last untill given condition is false Lodash
- Remove items begin from start until given condition is false Lodash
- Remove first n elements from an array using Lodash