Skip to main content

ECMAScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality ComparisonStrict Equality Comparison, includes compares using SameValueZeroSameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

Also unlike indexOf, includes does not skip missing indices:

new Array(5).includes(undefined); // true

Currently it's still a draft butIt can be polyfilledpolyfilled to make it work on all browsers.

ECMAScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

Also unlike indexOf, includes does not skip missing indices:

new Array(5).includes(undefined); // true

Currently it's still a draft but can be polyfilled to make it work on all browsers.

ECMAScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

Also unlike indexOf, includes does not skip missing indices:

new Array(5).includes(undefined); // true

It can be polyfilled to make it work on all browsers.

added 158 characters in body
Source Link
Oriol
  • 290.7k
  • 71
  • 459
  • 535

EcmaScriptECMAScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality ComparisonStrict Equality Comparison, includes compares using SameValueZeroSameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

ItAlso unlike indexOf, includes does not skip missing indices:

new Array(5).includes(undefined); // true

Currently it's still a draft but can be polyfilled to make it work on all browsers.

EcmaScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

It can be polyfilled to make it work on all browsers.

ECMAScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

Also unlike indexOf, includes does not skip missing indices:

new Array(5).includes(undefined); // true

Currently it's still a draft but can be polyfilled to make it work on all browsers.

added 1 character in body
Source Link
cнŝdk
  • 32.2k
  • 7
  • 62
  • 81

EcmaScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you tocan detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

It can be polyfilled to make it work on all browsers.

EcmaScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you to detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

It can be polyfilled to make it work on all browsers.

EcmaScript 7 introduces Array.prototype.includes.

It can be used like this:

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false

It also accepts an optional second argument fromIndex:

[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true

Unlike indexOf, which uses Strict Equality Comparison, includes compares using SameValueZero equality algorithm. That means that you can detect if an array includes a NaN:

[1, 2, NaN].includes(NaN); // true

It can be polyfilled to make it work on all browsers.

Source Link
Oriol
  • 290.7k
  • 71
  • 459
  • 535
Loading