From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- .../global_objects/array/unshift/index.html | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 files/pt-br/web/javascript/reference/global_objects/array/unshift/index.html (limited to 'files/pt-br/web/javascript/reference/global_objects/array/unshift') diff --git a/files/pt-br/web/javascript/reference/global_objects/array/unshift/index.html b/files/pt-br/web/javascript/reference/global_objects/array/unshift/index.html new file mode 100644 index 0000000000..bdf6c0e4d9 --- /dev/null +++ b/files/pt-br/web/javascript/reference/global_objects/array/unshift/index.html @@ -0,0 +1,90 @@ +--- +title: Array.prototype.unshift() +slug: Web/JavaScript/Reference/Global_Objects/Array/unshift +tags: + - Array + - JavaScript + - Prototype + - Referencia + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/Array/unshift +--- +
{{JSRef("Global_Objects", "Array")}}
+ +

Introdução

+ +

O método unshift() adiciona um ou mais elementos no início de um array e retorna o número de elementos (propriedade length) atualizado.

+ +

Sintaxe

+ +
arr.unshift([element1[, ...[, elementN]]])
+ +

Parâmetros

+ +
+
elementN
+
Os elementos a serem adicionados no começo do array.
+
+ +

Retorna

+ +

A nova propriedade {{jsxref("Array.length", "length")}} do objeto acima onde o método foi chamado.

+ +

Descrição

+ +

O método unshift insere os valores fornecidos no início de um objeto do tipo array.

+ +

unshift é intencionalmente genérico; este método pode ser chamado via {{jsxref("Function.call", "call", "", 1)}} ou {{jsxref("Function.apply", "apply", "", 1)}} em objetos que se assemelham aos arrays. Objetos que não contêm uma propriedade length que reflete a última de uma série consecutiva de propriedades numéricas, iniciada por 0, podem não comportar-se de maneira significativa.

+ +

Exemplos

+ +
var arr = [1, 2];
+
+arr.unshift(0); // result of call is 3, the new array length
+// arr is [0, 1, 2]
+
+arr.unshift(-2, -1); // = 5
+// arr is [-2, -1, 0, 1, 2]
+
+arr.unshift([-3]);
+// arr is [[-3], -2, -1, 0, 1, 2]
+
+ +

Especificações

+ + + + + + + + + + + + + + + + + + + + + + + + +
EspecificaçãoStatusComentário
ECMAScript 3ª EdiçãoPadrãoDefinição inicial. Implementado no JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.4.4.13', 'Array.prototype.unshift')}}{{Spec2('ES5.1')}}
{{SpecName('ES6', '#sec-array.prototype.unshift', 'Array.prototype.unshift')}}{{Spec2('ES6')}}
+ +

Compatibilidade entre browsers

+ +
{{Compat("javascript.builtins.Array.unshift")}}
+ +

Veja também

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