Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bendingbender/mdn-array.prototype.includes
MDN version of Array.prototype.includes shim
https://github.com/bendingbender/mdn-array.prototype.includes
Last synced: 25 days ago
JSON representation
MDN version of Array.prototype.includes shim
- Host: GitHub
- URL: https://github.com/bendingbender/mdn-array.prototype.includes
- Owner: BendingBender
- License: cc0-1.0
- Created: 2016-08-03T14:39:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-11T19:44:21.000Z (over 7 years ago)
- Last Synced: 2024-11-20T18:12:00.158Z (about 1 month ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![browser support](https://ci.testling.com/BendingBender/MDN-Array.prototype.includes.png)](https://ci.testling.com/BendingBender/MDN-Array.prototype.includes)
[![Build Status](https://travis-ci.org/BendingBender/MDN-Array.prototype.includes.svg?branch=master)](https://travis-ci.org/BendingBender/MDN-Array.prototype.includes)
# ES6 `Array.prototype.includes` shim
Simple ES6 [Array.prototype.includes](https://tc39.github.io/ecma262/#sec-array.prototype.includes) polyfill for older environments taken from [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Polyfill).
For browsers only, bower-friendly. Explicitly not meant to be used with node, use [array-includes](https://github.com/ljharb/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, returning `true` or `false` as appropriate.
#### Parameters
* `searchElement`: The element to search for.
* `fromIndex`: Optional. The position in this array at which to begin searching for `searchElement`. A negative value searches from the index of array.length + fromIndex by asc. Defaults to 0.#### Code example
```javascript
[1, 5, 7, 10].includes(5) // true
[1, 5, NaN, 10].includes(NaN) // true
```## Acknowledgements
Readme partially taken from [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes).
Tests taken from [array-includes](https://github.com/ljharb/array-includes).## License
CC0 1.0