Instance Method インスタンスメソッド

remove(at:)

Removes and returns the element at the specified position. 指定された位置での要素を削除して返します。

Declaration 宣言

@discardableResult mutating func remove(at index: Int) -> Element

Parameters パラメータ

index

The position of the element to remove. index must be a valid index of the array. 削除する要素の位置。indexは配列の有効なインデックスでなければなりません。

Return Value 戻り値

The element at the specified index. 指定されたインデックスでの要素。

Discussion 解説

All the elements following the specified position are moved up to close the gap. 指定された位置に続く要素すべては、隔たりを埋めるように繰り上げられます。


var measurements: [Double] = [1.1, 1.5, 2.9, 1.2, 1.5, 1.3, 1.2]
let removed = measurements.remove(at: 2)
print(measurements)
// Prints "[1.1, 1.5, 1.2, 1.5, 1.3, 1.2]"

Complexity: O(n), where n is the length of the array. 計算量:O(n)、ここでnは配列の長さです。

Relationships 関係

From Protocol 由来プロトコル

See Also 参照

Removing Elements 要素の削除