---
title: "subscript(_:)"
framework: foundation
role: symbol
role_heading: Instance Subscript
path: "foundation/nsarray/subscript(_:)"
---

# subscript(_:)

Returns the object at the specified index.

## Declaration

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

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

## Parameters

- `idx`: An index within the bounds of the array.

## Return Value

Return Value The object located at idx.

## Discussion

Discussion This method has the same behavior as the 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 is raised. You shouldn’t need to call this method directly. Instead, this method is called when accessing an object by index using subscripting. id value = array[3]; // equivalent to [array objectAtIndex:3]

## See Also

### Querying an Array

- [contains(_:)](foundation/nsarray/contains(_:).md)
- [count](foundation/nsarray/count.md)
- [firstObject](foundation/nsarray/firstobject.md)
- [lastObject](foundation/nsarray/lastobject.md)
- [object(at:)](foundation/nsarray/object(at:).md)
- [objects(at:)](foundation/nsarray/objects(at:).md)
- [objectEnumerator()](foundation/nsarray/objectenumerator().md)
- [reverseObjectEnumerator()](foundation/nsarray/reverseobjectenumerator().md)
