删除数组中的第一个和最后一个元素 [英] to remove first and last element in array

查看:40
本文介绍了删除数组中的第一个和最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆