删除数组中的第一个和最后一个元素 [英] to remove first and last element in array
本文介绍了删除数组中的第一个和最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何删除数组中的第一个和最后一个元素?
How to remove first and last element in an array?
例如:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
预期输出数组:
["Orange", "Apple"]
推荐答案
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.
这篇关于删除数组中的第一个和最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文