Nuestros voluntarios aún no han traducido este artículo al Español. ¡Únete a nosotros y ayuda a traducirlo!
This is an experimental technology, part of the ECMAScript 2016 (ES7) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.
The includes() method determines whether an array includes a certain element, returning true or false as appropriate.
Syntax
array.includes(searchElement[, fromIndex])
Parameters
searchElement- The element to search for.
fromIndex- Optional. The position in this array at which to begin searching for
searchElement; defaults to 0.
Examples
[1, 2, 3].includes(2); // true [1, 2, 3].includes(4); // false [1, 2, 3].includes(3, 3); // false [1, 2, 3].includes(3, -1); // true [1, 2, NaN].includes(NaN); // true
Polyfill
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
'use strict';
var O = Object(this);
var len = parseInt(O.length) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1]) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {k = 0;}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)) {
return true;
}
k++;
}
return false;
};
}
Specification
Proposal: Array.prototype.includes
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 47 | 43 | Not supported | 34 | 9 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | Not supported | 47 | 43 | Not supported | 34 | 9 |
See also
Etiquetas y colaboradores del documento
Etiquetas:
Contributors to this page: tschneidereit, DomenicDenicola, alexlur, fscholz, SphinxKnight, havenchyk, aaylward, Brettz9, ziyunfei, ablaze8, Mingun
Última actualización por:
tschneidereit,