to remove first and last element in array

后端 未结 12 802
鱼传尺愫
鱼传尺愫 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:42

    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. 
    

    See all methods for an Array.

提交回复
热议问题