# getAtIndex

Source: https://taxilang.org/docs/language/stdlib/getAtIndex

**Full name:** `taxi.stdlib.getAtIndex`

## Signature

```taxi
declare extension function <T> getAtIndex(collection: T[], index: Int):T
```

## Description

Returns the item at the provided index in the collection. Throws an error if the index is out of bounds.

This function retrieves an element at a specific position in a collection, with zero-based indexing.

```taxi
// Get the second item in a list
find { playlist: Playlist } as {
   secondSong: playlist.songs.getAtIndex(1) // Note: index starts at 0
}
```

## Examples

Retrieves a song from a playlist by its zero-based index position.

Schema:

```taxi
model Song {
   title: Title inherits String
   artist: Artist inherits String
   duration: Duration inherits Int
}
model Playlist {
   name: PlaylistName inherits String
   songs: Song[]
}
```

Query:

```taxi
given {
   playlist: Playlist = {
      name: 'Road Trip Mix',
      songs: [
         { title: 'Highway Star', artist: 'Deep Purple', duration: 372 },
         { title: 'Born to Run', artist: 'Bruce Springsteen', duration: 270 },
         { title: 'Life in the Fast Lane', artist: 'Eagles', duration: 251 }
      ]
   }
}
find {
   playlistName: PlaylistName
   firstSong: Song = Song[].getAtIndex(0)
   secondSong: Song = Song[].getAtIndex(1)
}
```

Result:

```json
{
  "playlistName": "Road Trip Mix",
  "firstSong": {
    "title": "Highway Star",
    "artist": "Deep Purple",
    "duration": 372
  },
  "secondSong": {
    "title": "Born to Run",
    "artist": "Bruce Springsteen",
    "duration": 270
  }
}
```
