配列の最初と最後の要素を削除するには質問する

配列の最初と最後の要素を削除するには質問する

配列内の最初と最後の要素を削除するにはどうすればよいですか?

例えば:

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

期待される出力配列:

["Orange", "Apple"]

ベストアンサー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. 

配列のすべてのメソッドを参照してください。

おすすめ記事