// 示例代码:使用 pop() 函数
// 定义一个数组
let fruits = ['苹果', '香蕉', '橙子'];
// 使用 pop() 函数移除并返回数组的最后一个元素
let lastFruit = fruits.pop();
// 输出被移除的元素
console.log(lastFruit); // 输出: 橙子
// 输出修改后的数组
console.log(fruits); // 输出: ['苹果', '香蕉']
pop()
函数用于移除数组的最后一个元素,并返回该元素。原数组会被修改,长度减 1。