Array.prototype.pop() 方法用于移除数组最后一个成员,并返回该数组成员。
arr.pop();
返回值: 返回被移除的数组成员。如果该数组为空(没有任何元素),则返回 undefined。
call() 或 apply() 一起使用时,可应用在类数组对象上。pop 方法根据 length 属性来确定最后一个元素的位置。如果不包含 length 属性或 length 属性不能被转成一个数值,会将 length 置为 0,并返回 undefined。length 属性也会随之改变(如果数组中有元素的话),一般而言,数组的 length 属性将会减 1。pop(),它返回 undefined。let foo = ['a', 'b', 'c', 'd'];let popped = foo.pop();console.log(foo);// ['a', 'b', 'c', 'd']console.log(popped);// 'd'
let empty = [];let popped = empty.pop();console.log(popped);// undefinedconsole.log(empty);// []