subscript(_:)
Accesses the element at the specified position.
Declaration
subscript(index: Int) -> Element { get set }Parameters
- index:
The position of the element to access.
indexmust be greater than or equal tostartIndexand less thanendIndex.
Overview
The following example uses indexed subscripting to update an array’s second element. After assigning the new value ("Butler") at a specific position, that value is immediately available at that same position.
var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
streets[1] = "Butler"
print(streets[1])
// Prints "Butler"