JavaScript, Array

Checks if all the elements in values are included in arr.

  • Use Array.prototype.every() and Array.prototype.includes() to check if all elements of values are included in arr.
const includesAll = (arr, values) => values.every(v => arr.includes(v));
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false

Recommended snippets

  • includesAny

    JavaScript, Array

    Checks if at least one element of values is included in arr.

  • findLastIndex

    JavaScript, Array

    Finds the index of the last element for which the provided function returns a truthy value.

  • pullAtIndex

    JavaScript, Array

    Mutates the original array to filter out the values at the specified indexes. Returns the removed elements.