0

I wish to check that all the values in event are included in state. Is so the function should return true, else false. What is a nice way of doing this?

const state = [1,2,4,5,6,7]
const event = [1,2]
if(state.contains(event))(}
Baz
  • 12,713
  • 38
  • 145
  • 268

1 Answers1

3

You can use every() and includes() array methods:

const state = [1, 2, 4, 5, 6, 7];
const event = [1, 2];
console.log(event.every(x => state.includes(x)));
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177