Files
30-seconds-of-code/snippets/includesAll.md
2022-06-08 12:30:49 +03:00

22 lines
561 B
Markdown

---
title: Check if array includes all values
tags: array
expertise: beginner
cover: blog_images/tomatoes.jpg
firstSeen: 2019-11-04T21:37:16+02:00
lastUpdated: 2020-10-20T23:02:01+03:00
---
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`.
```js
const includesAll = (arr, values) => values.every(v => arr.includes(v));
```
```js
includesAll([1, 2, 3, 4], [1, 4]); // true
includesAll([1, 2, 3, 4], [1, 5]); // false
```