# Array Index

*noun*

say it: **“uh-RAY IN-deks”** **/əˈreɪ ˈɪndɛks/**

The number of a slot in an array, counted from 0, used to read or change the item in that slot.

## What is an **array index** in bash?

An **array index** is the number of a slot in an array. Bash counts from 0, so the index says how many slots from the start: the first song is 0 and the third is 2. `${songs[-1]}` is the last item, and `"${!songs[@]}"` lists every index, handy for numbering a list.

```bash
songs=("Highway Tea" "Paper Lanterns" "Window Down")
echo "${songs[2]}"     # Window Down
echo "${songs[-1]}"    # Window Down
for i in "${!songs[@]}"; do echo "$((i + 1)). ${songs[$i]}"; done
# 1. Highway Tea
# 2. Paper Lanterns
# 3. Window Down
```

## In a sentence

- “The third song sits at **array index** 2, because bash counts from 0.”
- “Sam looped over every **array index** to print the songs as a numbered list.”

Level: Journeyman · [More Unix terms at this level](https://www.ask-codey.com/glossary?category=unix&level=3)

Updated: November 10, 2026

## In other subjects

- [Array Index in C#](https://www.ask-codey.com/glossary/array-index-c-sharp)
- [Array Index in Java](https://www.ask-codey.com/glossary/array-index)
- [Array Index in JavaScript](https://www.ask-codey.com/glossary/array-index-javascript)
- [Array Index in PowerShell](https://www.ask-codey.com/glossary/array-index-powershell)

Source: https://www.ask-codey.com/glossary/array-index-unix
