配列の最後の値を取り出す Array.pop
ひとことで言うと
配列から最後の要素を削除し、その値を返します。
ブロックとコード
配列から最後の値を削除して返す
ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。
["hello"].pop()["hello"].pop()使用例
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