<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/ArraySlice/subscript(_:)-4e8d9",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s10ArraySliceVyxSicip"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Accesses the element at the specified position.

```
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

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"
```

> Complexity: 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)