作用:

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():增加元素到数组开端。