Categories
JavaScript Answers

How to do the opposite of includes with JavaScript arrays?

Spread the love

To do the opposite of includes with JavaScript arrays, we negate the return value of includes.

For instance, we write

const res = filteredResult.filter((e) => !e.selectedFields.includes("Red"));

to call filter with a callback that checks if object e‘s selectedFields property in filteredResult being looped through doesn’t include 'Red'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *