作用:
pop()方法从数组中删除最后一个元素,并返回该元素的值
语法:
arr.pop()
注意:
此方法改变数组的长度!
当数组为空时返回undefined
实例:
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
console.log(plants.pop());
// expected output: "tomato"
console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
plants.pop();
console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage"]
拓展
pop():删除数组末尾的元素。
shift():删除数组最前面(头部)的元素。
unshift():添加元素到数组的头部。
push():添加元素到数组末尾。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。