<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSArray/subscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Subscript",
  "symbol" : {
    "kind" : "Instance Subscript",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSArray(im)objectAtIndexedSubscript:"
  },
  "title" : "subscript(_:)"
}
-->

# subscript(_:)

Returns the object at the specified index.

```
subscript(idx: Int) -> Any { get }
```

## Parameters

`idx`

An index within the bounds of the array.

## Return Value

The object located at `idx`.

## Discussion

This method has the same behavior as the [`object(at:)`](/documentation/Foundation/NSArray/object(at:)) method.

If `idx` is beyond the end of the array (that is, if `idx` is greater than or equal to the value returned by `count`), an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) is raised.

You shouldn’t need to call this method directly. Instead, this method is called when accessing an object by index using subscripting.

```objc
id value = array[3]; // equivalent to [array objectAtIndex:3]
```

## See Also

[`setObject:atIndexedSubscript:`](/documentation/Foundation/NSMutableArray/setObject:atIndexedSubscript:)

Replaces the object at the index with the new object, possibly adding the object.



---

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)