Is it possible to avoid point in this example?
JavaScript
x
3
1
_.reject([1, 4, null, undefined, 2, 5], item => _.isNull(item) || _.isUndefined(item));
2
// -> [1, 4, 2, 5]
3
Advertisement
Answer
Reject all items that are undefined
or null
using _.isNil()
:
JavaScript
1
3
1
const result = _.reject([1, 4, null, undefined, 2, 5], _.isNil);
2
3
console.log(result);
JavaScript
1
1
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>