Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opposite of filter es2016

I do below code when I've done removed a user.

users.filter(obj => obj.id === user.id);

It's wrong because now my users object left one user object, instead I should remove the item from the list base on the id. So I wonder is there any opposite of filter function?

like image 760
Alan Jenshen Avatar asked Dec 03 '25 14:12

Alan Jenshen


1 Answers

The opposite of filter is filter. You just need to specify what you want to keep.

For example, if you want odd numbers:

[1,2,3,4,5,6].filter(x => x%2 != 0);

if you want the opposite:

[1,2,3,4,5,6].filter(x => x%2 == 0);
like image 155
slebetman Avatar answered Dec 06 '25 05:12

slebetman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!