All Projects → es-shims → array-includes

es-shims / array-includes

Licence: MIT license
Array.prototype.includes spec-compliant polyfill

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to array-includes

Array.prototype.at
An ES-spec-compliant (proposed) `Array.prototype.at`shim/polyfill/replacement that works as far down as ES3.
Stars: ✭ 20 (-52.38%)
Mutual labels:  polyfill, array, shim
String.prototype.trim
ES5 spec-compliant shim for String.prototype.trim
Stars: ✭ 13 (-69.05%)
Mutual labels:  polyfill, shim
Core Js
Standard Library
Stars: ✭ 15,854 (+37647.62%)
Mutual labels:  polyfill, shim
Object.getOwnPropertyDescriptors
Spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5.
Stars: ✭ 19 (-54.76%)
Mutual labels:  polyfill, shim
object-keys
Object.keys shim
Stars: ✭ 41 (-2.38%)
Mutual labels:  polyfill, shim
String.prototype.matchAll
Spec-compliant polyfill for String.prototype.matchAll, in ES2020
Stars: ✭ 14 (-66.67%)
Mutual labels:  polyfill, shim
Promise.allSettled
ES Proposal spec-compliant shim for Promise.allSettled
Stars: ✭ 93 (+121.43%)
Mutual labels:  polyfill, shim
Proposal Array Unique
ECMAScript proposal for Deduplicating method of Array
Stars: ✭ 96 (+128.57%)
Mutual labels:  polyfill, array
barcode-detector
Spec compliant polyfill of the Barcode Detection API 🤳
Stars: ✭ 31 (-26.19%)
Mutual labels:  polyfill, shim
smart-custom-element
Smart a lightweight web component library that provides capabilities for web components, such as data binding, using es6 native class inheritance. This library is focused for providing the developer the ability to write robust and native web components without the need of dependencies and an overhead of a framework.
Stars: ✭ 17 (-59.52%)
Mutual labels:  polyfill
php-helpers
An extensive set of PHP helper functions and classes.
Stars: ✭ 27 (-35.71%)
Mutual labels:  array
Ubigeo-Peru
Base de datos de departamentos, provincias y distritos del Perú (UBIGEO) actualizada al 2019 (El INEI ha actualizado hasta el 2016). SQL, JSON, XML, CSV, Arreglos PHP, YAML.
Stars: ✭ 113 (+169.05%)
Mutual labels:  array
polyfill-php74
This component provides functions unavailable in releases prior to PHP 7.4.
Stars: ✭ 26 (-38.1%)
Mutual labels:  polyfill
PHPUnit-Polyfills
Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests
Stars: ✭ 147 (+250%)
Mutual labels:  polyfill
xml-to-array
A simple class to convert an xml to array
Stars: ✭ 30 (-28.57%)
Mutual labels:  array
common
Metarhia Common Library
Stars: ✭ 55 (+30.95%)
Mutual labels:  array
cakephp-shim
CakePHP plugin to "shim" functionality up and down for major versions of the framework.
Stars: ✭ 37 (-11.9%)
Mutual labels:  shim
all-about-node
All about Node.js
Stars: ✭ 16 (-61.9%)
Mutual labels:  array
core2
The bare essentials of std::io for use in no_std. Alloc support is optional.
Stars: ✭ 67 (+59.52%)
Mutual labels:  polyfill
VBA-Better-Array
An array class for VBA providing features found in more modern languages
Stars: ✭ 77 (+83.33%)
Mutual labels:  array

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].