开发者社区 问答 正文

删除数组中的第一个和最后一个元素

如何删除数组中的第一个和最后一个元素?

例如:

var fruits = ["Banana", "Orange", "Apple", "Mango"]; 预期的输出数组:

["Orange", "Apple"]

展开
收起
保持可爱mmm 2020-02-08 12:38:00 562 分享 版权
1 条回答
写回答
取消 提交回答
  • fruits.shift(); // Removes the first element from an array and returns only that element. fruits.pop(); // Removes the last element from an array and returns only that element. 查看数组的所有方法。

    2020-02-08 12:38:12
    赞同 展开评论
问答地址: