Skip to content
Advertisement

Lodash reject point free

Is it possible to avoid point in this example?

_.reject([1, 4, null, undefined, 2, 5], item => _.isNull(item) || _.isUndefined(item));
// -> [1, 4, 2, 5]

Advertisement

Answer

Reject all items that are undefined or null using _.isNil():

const result = _.reject([1, 4, null, undefined, 2, 5], _.isNil);

console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement