Array.prototype.includes
shim
ES6 Simple ES6 Array.prototype.includes polyfill for older environments taken from MDN.
For browsers only, bower-friendly. Explicitly not meant to be used with node, use array-includes if you wish a shim for node.
Installation
- Just include repo before your scripts.
bower install mdn-array.prototype.includes
Usage
-
Array.prototype.includes(searchElement[, fromIndex])
determines whether an array includes a certain element, returningtrue
orfalse
as appropriate.
Parameters
-
searchElement
: The element to search for. -
fromIndex
: Optional. The position in this array at which to begin searching forsearchElement
. A negative value searches from the index of array.length + fromIndex by asc. Defaults to 0.
Code example:
// Default:
[1, 5, 7, 10].includes(5) // true
[1, 5, NaN, 10].includes(NaN) // true
Acknowledgements
Readme partially taken from MDN. Tests taken from array-includes.
License
CC0 1.0