Array.prototype.pop()

pop()方法从数组中删除最后一个元素,并返回该元素的值。此方法更改数组的长度。

语法

arr.pop()

返回值

从数组中删除的元素(当数组为空时返回undefined)。

描述

pop 方法从一个数组中删除并返回最后一个元素。

pop 方法有意具有通用性。该方法和 apply() 一起使用时,可应用在类似数组的对象上。pop方法根据 length属性来确定最后一个元素的位置。如果不包含length属性或length属性不能被转成一个数值,会将length置为0,并返回undefined

如果你在一个空数组上调用 pop(),它返回  undefined

示例

例子: 删除掉数组的最后一个元素

下面的代码首先创建了一个拥有四个元素的数组 myFish,然后删除掉它的最后一个元素。

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

let popped = myFish.pop();

console.log(myFish); 
// ["angel", "clown", "mandarin"]

console.log(popped); 
// surgeon

规范

Specification Status Comment
ECMAScript 3rd Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.2.
ECMAScript 5.1 (ECMA-262)
Array.prototype.pop
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
Array.prototype.pop
Standard  
ECMAScript Latest Draft (ECMA-262)
Array.prototype.pop
Draft  

浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
pop Chrome Full support 1 Edge Full support 12 Firefox Full support 1 IE Full support 5.5 Opera Full support Yes Safari Full support Yes WebView Android Full support Yes Chrome Android Full support 18 Firefox Android Full support 4 Opera Android Full support Yes Safari iOS Full support Yes Samsung Internet Android Full support Yes nodejs Full support Yes

Legend

Full support  
Full support

相关链接