| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift | [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 julio de 2015.
El mtodo unshift() agrega uno o ms elementos al inicio del array, y devuelve la nueva longitud del array.
const array1 = [1, 2, 3];
console.log(array1.unshift(4, 5));
// Expected output: 5
console.log(array1);
// Expected output: Array [4, 5, 1, 2, 3]
arr.unshift(elemento1[, ...[, elementoN]])
elementoNElementos a agregar al inicio del array.
La nueva propiedad length del objeto sobre el cual el mtodo fue llamado.
El mtodo unshift inserta los valores proporcionados al inicio de un objeto del tipo array.
unshift es intencionalmente genrico; este mtodo puede ser called o applied a objetos similares a arrays. Objetos que no contengan una propiedad length reflejando una serie de propiedades numricas consecutivas, comenzada a partir del cero, pueden no comportarse de una manera comprensible.
var arr = [1, 2];
arr.unshift(0); // resultado de la llamada es 3, la nueva longitud del array
// arr es [0, 1, 2]
arr.unshift(-2, -1); // = 5
// arr es [-2, -1, 0, 1, 2]
arr.unshift([-3]);
// arr es [[-3], -2, -1, 0, 1, 2]
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.unshift |
This page was last modified on 11 feb 2025 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 |