to remove first and last element in array

后端 未结 12 794
鱼传尺愫
鱼传尺愫 2020-12-04 16:14

How to remove first and last element in an array?

For example:

var fruits = [\"Banana\", \"Orange\", \"Apple\", \"Mango\"];

Expecte

12条回答
  •  执念已碎
    2020-12-04 16:43

    To remove the first and last element of an array is by using the built-in method of an array i.e shift() and pop() the fruits.shift() get the first element of the array as "Banana" while fruits.pop() get the last element of the array as "Mango". so the remaining element of the array will be ["Orange", "Apple"]

提交回复
热议问题