Inverse of [].filter in JS? Inverse of [].filter in JS? arrays arrays

Inverse of [].filter in JS?


You can use an arrow function:

const a = someArr.filter(someFilter);const a = someArr.filter(e => !someFilter(e));


Lodash provides a reject function that does the exact opposite of filter.

arr = _.reject(arr, filterFunc);


Take a look at lodash's negate function. It does exactly what @Yury Tarabanko mentions in his comment.

Usage:

arr = arr.filter(_.negate(filterFunc));