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
  • 11,687
  • 35
  • 137
  • 244

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
  • 80,501
  • 25
  • 149
  • 167