Socket
Socket
Sign inDemoInstall

array-includes

Package Overview
Dependencies
65
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-includes

An ES7/ES2016 spec-compliant `Array.prototype.includes` shim/polyfill/replacement that works as far down as ES3.


Version published
Weekly downloads
26M
decreased by-0.5%
Maintainers
1
Install size
3.16 MB
Created
Weekly downloads
 

Package description

What is array-includes?

The array-includes npm package provides a simple utility function for checking if an array includes a certain element, with optional support for the fromIndex parameter. It is a polyfill for the Array.prototype.includes method, which is part of the ECMAScript 2016 (ES7) standard but may not be available in all environments.

What are array-includes's main functionalities?

Check if an array includes a specific element

This feature allows you to check if an array contains a specific element. It returns true if the element is found, otherwise false.

var arrayIncludes = require('array-includes');
var myArray = [1, 2, 3];
var includesTwo = arrayIncludes(myArray, 2); // true

Check if an array includes a specific element starting from a given index

This feature allows you to check if an array contains a specific element, starting the search from a given index. It is useful when you want to ignore certain elements at the beginning of the array.

var arrayIncludes = require('array-includes');
var myArray = [1, 2, 3, 2];
var includesTwoFromIndex2 = arrayIncludes(myArray, 2, 2); // true

Other packages similar to array-includes

Changelog

Source

v3.1.6 - 2022-11-07

Commits

  • [meta] add auto-changelog c5fbe72
  • [meta] use npmignore to autogenerate an npmignore file dbd6dc8
  • [Deps] update es-abstract, get-intrinsic b819e3b
  • [actions] update rebase action to use reusable workflow 6e241d5
  • [Dev Deps] update aud, tape 9b2a931
  • [readme] note that FF 102+ no longer needs this package 0a0c758
<!-- auto-changelog-above -->

3.1.5 / 2022-05-03

  • [Fix] install polyfill on FF 99+
  • [Deps] update define-properties, es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, functions-have-names, safe-publish-latest, tape
  • [actions] reuse common workflows
  • [actions] update codecov uploader

3.1.4 / 2021-10-04

  • [Robustness] avoid a runtime Math.max call
  • [readme] add github actions/codecov badges
  • [readme] fix repo URLs; remove travis badge
  • [Deps] update es-abstract, is-string
  • [meta] use prepublishOnly script for npm 7+
  • [actions] update workflows
  • [actions] use node/install instead of node/run; use codecov action
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, tape

3.1.3 / 2021-02-20

  • [Deps] update call-bind, es-abstract, get-intrinsic
  • [meta] do not publish github action workflow files
  • [meta] gitignore coverage output
  • [actions] update workflows
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, functions-have-names, has-strict-mode, tape
  • [Tests] increase coverage

3.1.2 / 2020-11-24

  • [Robustness] remove dependency on .apply
  • [Deps] update es-abstract; use call-bind and get-intrinsic where applicable
  • [Dev Deps] update eslint, @ljharb/eslint-config, functions-have-names, tape; add aud, safe-publish-latest
  • [actions] add "Allow Edits" workflow
  • [actions] switch Automatic Rebase workflow to pull_request_target event
  • [Tests] migrate tests to Github Actions
  • [Tests] run nyc on all tests
  • [Tests] add implementation test; run es-shim-api in postlint; use tape runner

3.1.1 / 2019-12-21

  • [Fix] IE < 9 does not have index access on strings
  • [Deps] update es-abstract
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape
  • [meta] remove unused Makefile and associated utilities
  • [Tests] add string tests

3.1.0 / 2019-12-11

  • [New] add auto entry point
  • [Refactor] use split-up es-abstract (68% bundle size decrease)
  • [readme] fix repo URLs, remove testling, fix readme parsing
  • [Deps] update es-abstract, define-properties
  • [Dev Deps] update eslint, @ljharb/eslint-config, evalmd, covert, functions-have-names, replace, semver, tape, @es-shims/api, function-bind
  • [meta] add funding field, FUNDING.yml
  • [meta] Only apps should have lockfiles
  • [Tests] add more fromIndex tests
  • [Tests] use shared travis-ci configs
  • [Tests] use npx aud instead of nsp or npm audit with hoops
  • [Tests] remove jscs
  • [Tests] use functions-have-names
  • [Tests] use npm audit instead of nsp
  • [Tests] remove jscs
  • [actions] add automatic rebasing / merge commit blocking

3.0.3 / 2017-04-18

  • [Fix] ensure that shim.js actually shims when the polyfill differs from native
  • [Tests] up to node v7.9, v6.10, v4.8; comment out OS X builds; improve test matrix
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config, tape, jscs, semver, function-bind, @es-shims/api
  • [Deps] update es-abstract
  • [Docs] update readme: add “getting started” and “usage” (#19)

3.0.2 / 2015-06-06

  • Use the polyfill, not the implementation, as the default export
  • [Deps] update es-abstract
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config, semver
  • [Tests] up to node v5.5
  • [Tests] keep tests passing in node v0.8
  • [Tests] Only run evalmd as part of the full test suite, since it's more like a linter
  • [Tests] fix npm upgrades for older nodes

3.0.1 / 2015-05-23

  • [Fix] in "shim", assign the polyfill, not the implementation

3.0.0 / 2015-05-23

  • [Breaking] Implement the es-shim API
  • [Deps] update define-properties, es-abstract
  • [Dev Deps] update eslint, semver, nsp, semver, jscs
  • [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG
  • [Tests] use my personal shared eslint config
  • [Tests] up to io.js v3.0

2.0.0 / 2015-05-23

  • Fix to not skip holes, per https://github.com/tc39/Array.prototype.includes/issues/15

1.1.1 / 2015-05-23

  • Test up to io.js v2.0
  • Update es-abstract, tape, eslint, semver, jscs, semver

1.1.0 / 2015-03-19

  • Update es-abstract, editorconfig-tools, nsp, eslint, semver

1.0.6 / 2015-02-17

  • All grade A-supported node/iojs versions now ship with an npm that understands ^.
  • Run travis-ci tests on iojs and node v0.12; allow 0.8 failures.
  • Update tape, jscs, es-abstract, remove is.

1.0.5 / 2015-01-30

  • Update tape, jscs, nsp, eslint, es-abstract

1.0.4 / 2015-01-10

  • Use es-abstract for ECMAScript spec internal abstract operations

1.0.3 / 2015-01-06

  • Speed optimization: use Array#indexOf when available
  • Fix ES3, IE 6-8, Opera 10.6, Opera 11.1 support
  • Run testling on both sets of tests

1.0.2 / 2015-01-05

  • Ensure tests are includes in the module on npm

1.0.1 / 2015-01-04

  • Remove mistaken auto-shim.

1.0.0 / 2015-01-04

  • v1.0.0

Readme

Source

array-includes Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

Keywords

FAQs

Last updated on 08 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc