★ wanayoo — archive 1999 https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Array/popNouvelle recherche | Portail wanayoo

Array.prototype.pop()

Nossos voluntários ainda não traduziram este artigo para o Português (do Brasil). Junte-se a nós e ajude a fazer o trabalho!

Summary

The pop() method removes the last element from an array and returns that element.

Syntax

arr.pop()

Description

The pop method removes the last element from an array and returns that value to the caller.

pop is intentionally generic; this method can be called or applied to objects resembling arrays. Objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.

If you call pop() on an empty array, it returns an undefined value.

Example

Example: Removing the last element of an array

The following code creates the myFish array containing four elements, then removes its last element.

var myFish = ["angel", "clown", "mandarin", "surgeon"];

console.log("myFish before: " + myFish);

var popped = myFish.pop();

console.log("myFish after: " + myFish);
console.log("Removed this element: " + popped);

This example displays the following:

myFish before: angel,clown,mandarin,surgeon
myFish after: angel,clown,mandarin
Removed this element: surgeon

Specifications

Specification Status Comment
ECMAScript 3rd Edition Standard Initial definition. Implemented in JavaScript 1.2
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.prototype.pop' in that specification.
Standard  
ECMAScript 6 (ECMA-262)
The definition of 'Array.prototype.pop' in that specification.
Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 5.5 (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

Document Tags and Contributors

Última atualização por: fscholz,
Esconder painel