配列の最後の値を取り出す Array.pop

配列公式データ取得日:2026年11月13日動作確認待ち

ひとことで言うと

配列から最後の要素を削除し、その値を返します。

ブロックとコード

ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。

使用例

If you have an array with 4 numbers, like 1, 2, 3, and 4, you remove the last number from the array by popping it off of the end. To pop the number from the array in blocks, do this:

JavaScript

let thoseNumbers = [1, 2, 3, 4];
let lastNumber = thoseNumbers.pop();

Python

thoseNumbers = [1, 2, 3, 4]
lastNumber = thoseNumbers.pop()

Clean out your junk drawer but check if the scissors are in there. Do this by removing them from your list items in the drawer.

JavaScript

let found = false;
let junk = ["paper clip", "pencil", "notepad", "glue", "scissors", "screw driver"];
while (junk.length > 0) {
    if (junk.pop() == "scissors") {
        found = true;
    }
}

Python

found = False
junk = ["paper clip",
    "pencil",
    "notepad",
    "glue",
    "scissors",
    "screw driver"]
while len(junk) > 0:
    if junk.pop() == "scissors":
        found = True
執筆:鈴木孝昌官公庁のWeb・システム開発を担当する現役プロジェクトマネージャー。マイクラカップ沖縄代表チームを指導(第6回・第7回、第7回TBS賞)。
沖縄マイクラ部で、子どもたちにMakeCodeを教えています。プロフィールと編集方針
Instagramで教室の様子を見る
noteで記事を読む