---
title: "subscript(_:)"
framework: swift
role: symbol
role_heading: Instance Subscript
path: "swift/array/subscript(_:)-25iat"
---

# subscript(_:)

Accesses the element at the specified position.

## Declaration

```swift
subscript(index: Int) -> Element { get set }
```

## Parameters

- `index`: The position of the element to access. index must be greater than or equal to startIndex and less than endIndex.

## Overview

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" note: Reading an element from an array is O(1). Writing is O(1) unless the array’s storage is shared with another array or uses a bridged NSArray instance as its storage, in which case writing is O(n), where n is the length of the array.

## See Also

### Accessing Elements

- [first](swift/array/first.md)
- [last](swift/array/last.md)
- [subscript(_:)](swift/array/subscript(_:)-53fvb.md)
- [subscript(_:)](swift/array/subscript(_:)-3kwny.md)
- [subscript(_:)](swift/array/subscript(_:)-4h7rl.md)
- [subscript(_:)](swift/array/subscript(_:)-3pmfg.md)
- [randomElement()](swift/array/randomelement().md)
- [randomElement(using:)](swift/array/randomelement(using:).md)
