array-includes (3.1.9)
Published 2026-02-24 13:52:57 +00:00 by atheaadmin
Installation
registry=npm install array-includes@3.1.9"array-includes": "3.1.9"About this package
array-includes 
An ES7/ES2016 spec-compliant Array.prototype.includes shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.
Because Array.prototype.includes depends on a receiver (the this value), the main export takes the array to operate on as the first argument.
Engines that need this package include:
- IE (all versions)
- Safari < 9
- Firefox < 43, and 99-101
- Chrome < 47
- Edge < 14
- node < 6
Getting started
npm install --save array-includes
Usage
Basic usage: includes(array, value[, fromIndex=0])
var includes = require('array-includes');
var assert = require('assert');
var arr = [ 'one', 'two' ];
includes(arr, 'one'); // true
includes(arr, 'three'); // false
includes(arr, 'one', 1); // false
Example
var arr = [
1,
'foo',
NaN,
-0
];
assert.equal(arr.indexOf(0) > -1, true);
assert.equal(arr.indexOf(-0) > -1, true);
assert.equal(includes(arr, 0), true);
assert.equal(includes(arr, -0), true);
assert.equal(arr.indexOf(NaN) > -1, false);
assert.equal(includes(arr, NaN), true);
assert.equal(includes(arr, 'foo', 0), true);
assert.equal(includes(arr, 'foo', 1), true);
assert.equal(includes(arr, 'foo', 2), false);
/* when Array#includes is not present */
delete Array.prototype.includes;
var shimmedIncludes = includes.shim();
assert.equal(shimmedIncludes, includes.getPolyfill());
assert.equal(arr.includes('foo', 1), includes(arr, 'foo', 1));
/* when Array#includes is present */
var shimmedIncludes = includes.shim();
assert.equal(shimmedIncludes, Array.prototype.includes);
assert.equal(arr.includes(1, 'foo'), includes(arr, 1, 'foo'));
Tests
Simply clone the repo, npm install, and run npm test
Dependencies
Dependencies
| ID | Version |
|---|---|
| call-bind | ^1.0.8 |
| call-bound | ^1.0.4 |
| define-properties | ^1.2.1 |
| es-abstract | ^1.24.0 |
| es-object-atoms | ^1.1.1 |
| get-intrinsic | ^1.3.0 |
| is-string | ^1.1.1 |
| math-intrinsics | ^1.1.0 |
Development Dependencies
| ID | Version |
|---|---|
| @es-shims/api | ^2.5.1 |
| @ljharb/eslint-config | ^21.1.1 |
| auto-changelog | ^2.5.0 |
| encoding | ^0.1.13 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| functions-have-names | ^1.2.3 |
| has-strict-mode | ^1.1.0 |
| in-publish | ^2.0.1 |
| npmignore | ^0.3.1 |
| nyc | ^10.3.2 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.9.0 |
Keywords
Array.prototype.includes
includes
array
ES7
shim
polyfill
contains
Array.prototype.contains
es-shim API
