add description to array includes snippet since it looks a lot like es6 native includes function.
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
Use `slice()` to offset the array/string and `indexOf()` to check if the value is included.
|
Use `slice()` to offset the array/string and `indexOf()` to check if the value is included.
|
||||||
Omit the last argument, `fromIndex`, to check the whole array/string.
|
Omit the last argument, `fromIndex`, to check the whole array/string.
|
||||||
|
|
||||||
|
In [ES6](http://www.ecma-international.org/ecma-262/7.0/#sec-array.prototype.includes), you can use a similar native `.includes()` function.
|
||||||
```js
|
```js
|
||||||
const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1;
|
const includes = (collection, val, fromIndex=0) => collection.slice(fromIndex).indexOf(val) != -1;
|
||||||
// includes("30-seconds-of-code", "code") -> true
|
// includes("30-seconds-of-code", "code") -> true
|
||||||
|
|||||||
Reference in New Issue
Block a user