Rename js snippets
This commit is contained in:
21
snippets/js/s/array-includes-all-values.md
Normal file
21
snippets/js/s/array-includes-all-values.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Check if array includes all values
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [array]
|
||||
cover: tomatoes
|
||||
dateModified: 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
|
||||
```
|
||||
Reference in New Issue
Block a user