mdn-array.prototype.includes

MDN version of Array.prototype.includes shim


Keywords
mdn, polyfill, shim, array, prototype, array.prototype.includes, array.includes, includes, es6, es2015
License
CC0-1.0
Install
bower install mdn-array.prototype.includes

Documentation

browser support

Build Status

ES6 Array.prototype.includes shim

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, 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:

// 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