This chapter describes the ECMAScript 2016 feature “
Array.prototype.includes” by Domenic Denicola and Rick Waldron.
The Array method
includes has the following signature:
value is an element of its receiver (
includes is similar to
indexOf – the following two expressions are mostly equivalent:
The main difference is that
includes does not distinguish between
Typed Arrays will also have a method
hasis used for keys (
includesis used for elements (
String.prototype.includes). The elements of a Set can be viewed as being both keys and values, which is why there is a
String.prototype.includesworks with strings, not characters. Isn’t that inconsistent w.r.t.
includesworked exactly like string
includes, it would accept arrays, not single elements. But the two
includesfollow the example of
indexOf; characters are seen as a special case and strings with arbitrary lengths as the general case.
Array.prototype.includes(Domenic Denicola, Rick Waldron)