配列の指定した位置の値を削除する Array.removeAt
ひとことで言うと
特定の位置にある要素を削除し、その要素を返します。
ブロックとコード
配列から0番目の値を削除して返す
ブロックの文言は公式の日本語版に合わせています(形は簡易表示です)。
[""].removeAt(0)[""].remove_at(0)引数(ひきすう)
引数とは、ブロックの中で自分で選んだり入力したりする部分のことです。
| 名前 | 選べる値 | 意味 |
|---|---|---|
| index | 数値 |
使用例
The size of the array shrinks by one. The element is removed from the array at the position you want. All the other elements after it are moved (shifted) to down to the next lower position. So, an array that has the numbers 4, 5, 9, 3, 2 will be 4, 5, 3, 2 if 9 is removed from the array at index 2. It looks like this in blocks:
JavaScript
let myNumbers = [4, 5, 9, 3, 2]
let item = myNumbers.removeAt(2)Python
myNumbers = [4, 5, 9, 3, 2]
item = myNumbers.remove_at(2)Remove the most dangerous level of radiation from the list.
JavaScript
let radLevels = ["alpha", "beta", "gamma"]
let level = radLevels.indexOf("gamma")
let unzapped = radLevels.removeAt(level)Python
radLevels = ["alpha", "beta", "gamma"]
level = radLevels.index_of("gamma")
unzapped = radLevels.remove_at(level)