CodeDevStack

Check if all values in an array are present in another array

October 17, 2020

If you want to check if all values in an array are present in another array just use this snippet:

const list = [1, 2, 3];

[1, 2].every(value => list.includes(value)); //true
[1, 2, 4].every(value => list.includes(value)); //false

Be careful! If the array is empty, it will return true because of the way Array.prototype.every() works.

const list = [1, 2, 3];

[].every(value => list.includes(value)); //true !!!