| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/of | [Back] [Original] |
Get to know MDN better
Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since septiembre de 2015.
El mtodo Array.of() crea una nueva instancia Array con un nmero variable de elementos pasados como argumento, independientemente del nmero o del tipo.
La diferencia entre Array.of() y el constructor Array reside en como maneja los parmetros de tipo entero: Array.of(7) crea un array con un solo elemento, 7, mientras que Array(7) crea un array vaco con una propiedad length de 7 (Nota: esto implica un array de 7 ranuras vacas, no ranuras con valores undefined).
Array.of(7); // [7]
Array.of(1, 2, 3); // [1, 2, 3]
Array(7); // [ , , , , , , ]
Array(1, 2, 3); // [1, 2, 3]
Array.of(elemento0[, elemento1[, ...[, elementoN]]])
elementoNValores con los que se crear el Array en su respectivo indice.
Una nueva instancia de Array.
Esta funcin es parte del estndar ECMAScript 2015. Para obtener ms informacin, consulte Array.of y Array.from proposal y Array.of polyfill.
Array.of(1); // [1]
Array.of(1, 2, 3); // [1, 2, 3]
Array.of(undefined); // [undefined]
Escribiendo el siguiente cdigo antes que cualquier otro, podemos emular la funcionalidad de Array.of() si es que sta no est disponible de forma nativa.
if (!Array.of) {
Array.of = function () {
return Array.prototype.slice.call(arguments);
};
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.of |
This page was last modified on 5 ago 2023 by MDN contributors.
ArrayArray.prototype.at()Array.prototype.concat()Array.prototype.copyWithin()Array.prototype.entries()Array.prototype.every()Array.prototype.fill()Array.prototype.filter()Array.prototype.find()Array.prototype.findIndex()findLast()findLastIndex()Array.prototype.flat()Array.prototype.flatMap()Array.prototype.forEach()Array.prototype.includes()Array.prototype.indexOf()Array.prototype.join()Array.prototype.keys()Array.prototype.lastIndexOf()Array.prototype.map()Array.prototype.pop()Array.prototype.push()Array.prototype.reduce()Array.prototype.reduceRight()Array.prototype.reverse()Array.prototype.shift()Array.prototype.slice()Array.prototype.some()Array.prototype.sort()Array.prototype.splice()Array.prototype.toLocaleString()toReversed()Array.prototype.toSorted()toSpliced()Array.prototype.toString()Array.prototype.unshift()Array.prototype.values()with()Array.prototype[@@iterator]()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |