Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Array.prototype

Esta tradução está incompleta. Ajude atraduzir este artigo.

Resumo

A propriedade Array.prototype representa o protótipo para o construtor Array.

Property attributes of Array.prototype
Writable no
Enumerable no
Configurable no

Descrição

Instâncias de Array herdam de Array.prototype. Como em todos os construtores, você pode mudar o  protótipo desse construtor para modificar todas as instâncias de Array.

Um fato pouco conhecido: O próprio Array.prototype é um Array

Array.isArray(Array.prototype); // true

Propriedades

Array.prototype.constructor
Especifica a função que cria um objeto do protótipo.
 
Array.prototype.length
Reflete o número de elementos em um array.

Métodos

Métodos modificadores

Esses métodos modificam o array:

Array.prototype.copyWithin()
Copia uma sequência de elementos do array dentro do array.
Array.prototype.fill()
Preenche todos os elementos de um array com um elemento estático, começando de um índice inicial até um índice final.
Array.prototype.pop()
Remove e retorna o último elemento de um array.
Array.prototype.push()
Adiciona um ou mais elementos ao fim de um array e retorna o novo comprimeiro do array.
Array.prototype.reverse()
Reverte a ordem dos elementos de um array - o primeiro vira o último e o último vira o primeiro.
Array.prototype.shift()
Remove o primeiro elemento de um array e o retorna.
Array.prototype.sort()
Ordena os elementos do array em questão e retorna o array.
Array.prototype.splice()
Adiciona e/ou remove elementos de um array.
Array.prototype.unshift()
Adiciona um ou mais elementos ao início de um array e retorna o novo comprimento do array.

Métodos de acesso

Esses métodos não modificam o array, mas sim retornam alguma representação dele.

Array.prototype.concat()
Retorna um novo array formado por esse array concatenado com outro(s) array(s) e/ou valores.
Array.prototype.contains()
Verifica se o array possui cer, retornandotrue ou false apropriadamente.
Array.prototype.join()
Retorna uma string com todos os elementos do array
Array.prototype.slice()
Retorna um novo array com uma parte do array sobre o qual o método foi chamado
Array.prototype.toSource()
Retorna um array literal representando o array especificado; você pode usar esse valor para criar um novo array. Esse método sobrescreve o método Object.prototype.toSource().
Array.prototype.toString()
Retonar uma string representando o array e seus elementos. Esse método sobrescreve o método Object.prototype.toString().
Array.prototype.toLocaleString()
Retonar uma string adequada ao idioma do usuário representando o array e seus elementos. Esse método sobrescreve o método Object.prototype.toLocaleString().
Array.prototype.indexOf()
Representa o índice da primeira ocorrência de um valor especificado no array, ou -1 se o valor não estiver incluso no array.
Array.prototype.lastIndexOf()
Representa o índice da última ocorrência de um valor especificado no array, ou -1 se o valor não estiver incluso no array

Iteration methods

Several methods take as arguments functions to be called back while processing the array. When these methods are called, the length of the array is sampled, and any element added beyond this length from within the callback is not visited. Other changes to the array (setting the value of or deleting an element) may affect the results of the operation if the method visits the changed element afterwards. While the specific behavior of these methods in such cases is well-defined, you should not rely upon it so as not to confuse others who might read your code. If you must mutate the array, copy into a new array instead.

Array.prototype.forEach()
Calls a function for each element in the array.
Array.prototype.entries()
Returns a new Array Iterator object that contains the key/value pairs for each index in the array.
Array.prototype.every()
Returns true if every element in this array satisfies the provided testing function.
Array.prototype.some()
Returns true if at least one element in this array satisfies the provided testing function.
Array.prototype.filter()
Creates a new array with all of the elements of this array for which the provided filtering function returns true.
Array.prototype.find()
Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found.
Array.prototype.findIndex()
Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found.
Array.prototype.keys()
Returns a new Array Iterator that contains the keys for each index in the array.
Array.prototype.map()
Creates a new array with the results of calling a provided function on every element in this array.
Array.prototype.reduce()
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
Array.prototype.reduceRight()
Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
Array.prototype.values()
Returns a new Array Iterator object that contains the values for each index in the array.
Array.prototype[@@iterator]()
Returns a new Array Iterator object that contains the values for each index in the array.

Métodos genéricos

Vários métodos do objeto Array em Javascript foram feitos para serem aplicados genericamentes em todos os objetos que "pareçam" Arrays. Isso é, eles podem ser usados em qualquer objeto que possuam uma propriedade length (comprimento), e que possa ser usado a partir de propriedades numéricas (como índices no formato array[5]). Alguns métodos, como join, apenas lêem e as propriedades numéricas do objeto sobre o qual eles sãochamados. Outros, como reverse, exigem que as propriedades numéricas e length sejam mutáveis; sendo assim, esses métodos não podem ser chamados em objetos como String, que não permitem que nenhuma das duas propriedades sejam modificadas.

Especifiações

Especificação Status Comentário
ECMAScript 1st Edition. Padrão Definição inicial
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.prototype' in that specification.
Standard  
ECMAScript 6 (ECMA-262)
The definition of 'Array.prototype' in that specification.
Release Candidate  

Compatibilidade com Navegadore

Característica Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Característica Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

Veja também

Etiquetas do documento e colaboradores

 Colaboradores desta página: danielbastos
 Última atualização por: danielbastos,