From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../global_objects/array/shift/index.html | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/array/shift/index.html (limited to 'files/es/web/javascript/reference/global_objects/array/shift/index.html') diff --git a/files/es/web/javascript/reference/global_objects/array/shift/index.html b/files/es/web/javascript/reference/global_objects/array/shift/index.html new file mode 100644 index 0000000000..7391f6c325 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/array/shift/index.html @@ -0,0 +1,124 @@ +--- +title: Array.prototype.shift() +slug: Web/JavaScript/Referencia/Objetos_globales/Array/shift +translation_of: Web/JavaScript/Reference/Global_Objects/Array/shift +--- +
{{JSRef}}
+ +

El método shift() elimina el primer elemento del array y lo retorna. Este método modifica la longitud del array.

+ +

Sintaxis

+ +
arr.shift()
+ +

Descripción

+ +

El método shift elimina el elemento en el índice cero y desplaza los valores consecutivos hacia abajo, devolviendo el valor eliminado. Si la propiedad {{jsxref("Array.length", "length")}} es 0, devuelve {{jsxref("undefined")}}.

+ +

shift es genérico; este método puede utilizarse con {{jsxref("Function.call", "call", "", 1)}} o {{jsxref("Function.apply", "apply", "", 1)}} a objetos simliares a arrays. Los objetos que no tengan una propiedad length que refleje el último elemento de una serie consecutiva de propiedades numéricas con índice base cero pueden no comportarse de manera significativa.

+ +

Ejemplos

+ +

Eliminando un elemento de un array

+ +

El siguiente código muestra el contenido del array miPescado antes y después de eliminar el primer elemento. También muestra el elemento eliminado:

+ +
var miPescado = ['ángel', 'payaso', 'mandarín', 'cirujano'];
+
+console.log('miPescado antes: ' + miPescado);
+// "miPescado antes: ángel,payaso,mandarín,cirujano"
+
+var eliminado = miPescado.shift();
+
+console.log('miPescado después: ' + miPescado);
+// "miPescado after: payaso,mandarín,cirujano"
+
+console.log('Elemento eliminado: ' + eliminado);
+// "Elemento eliminado: ángel"
+ +

Especificaciones

+ + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES3')}}{{Spec2('ES3')}}Definición inicial. Implementado en Javascript 1.2.
{{SpecName('ES5.1', '#sec-15.4.4.9', 'Array.prototype.shift')}}{{Spec2('ES5.1')}}
{{SpecName('ES6', '#sec-array.prototype.shift', 'Array.prototype.shift')}}{{Spec2('ES6')}}
+ + + +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Soporte básico{{CompatChrome("1.0")}}{{CompatGeckoDesktop("1.7")}}{{CompatIE("5.5")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Soporte básico{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Ver también

+ + -- cgit v1.2.3-54-g00ecf