Categories
JavaScript Answers

How to check whether multiple values exist within a JavaScript array?

Spread the love

To check whether multiple values exist within a JavaScript array, we use the every and includes methods.

For instance, we write

const success = arrayA.every((val) => arrayB.includes(val));

to call arrayA.every with a callback that checks if every val in arrayA is in “arrayBwithincludes`.

If the condition is met for all elements in arrayA, then true is return.

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 *