1. ホーム
  2. javascript

[解決済み] 配列の最初と最後の要素を削除する

2022-08-14 16:20:08

質問

配列の最初と最後の要素を削除する方法は?

例えば

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. 

Arrayの全てのメソッドを見る。