An array is an ordered collection of values stored under a single name, where each value sits at a numbered position called an index. Instead of score1, score2, score3, you keep one array scores and reach any element by its index. Arrays are one of the most fundamental data structures in programming, the backbone of lists, grids, and countless algorithms. The concept is simple, but the details, zero-based indexing and the performance trade-offs, are exactly where beginners stumble in 2026.
The core idea
An array lines up values in order and gives each a position. You access an element by its index, and in most languages the first index is 0, not 1.
// An array of three values; the first is at index 0
scores = [90, 85, 100]
print(scores[0]) // prints 90, the first element
print(scores[2]) // prints 100, the third element
scores[1] = 88 // change the second element
The index is the address within the array. Because the values sit next to each other in memory, the computer can jump straight to any position by simple math, which is why indexed access is so fast.
Why indexing is fast and insertion is slow
| Operation |
Speed |
Why |
| Access by index |
Constant time |
Jump directly to the position |
| Update by index |
Constant time |
Same direct jump |
| Append at the end |
Usually fast |
Often just the next slot |
| Insert in the middle |
Slow |
Later elements must shift over |
| Search by value |
Slow unless sorted |
May scan every element |
This trade-off defines arrays. They are unbeatable for reading by position and iterating in order, but inserting or deleting in the middle forces the language to shift everything after it, which gets expensive on large arrays.
Arrays vs lists vs other structures
Terminology varies by language, which causes confusion.
- In Python, the built-in
list is a dynamic array: it grows automatically as you add elements.
- In JavaScript,
Array is similarly dynamic.
- In C, C++, Java, a classic array has a fixed size set when created; you use other structures (vectors, ArrayLists) to grow.
- A linked list is different: it stores elements scattered in memory linked by pointers, making middle insertion fast but indexed access slow. Those links rely on a pointer in 2026.
So when someone says array, check whether they mean a fixed-size low-level array or a dynamic, growable one.
Working with arrays
- Iterate in order with a loop to process every element.
- Map and filter in higher-level languages to transform or select elements without manual loops.
- Use multidimensional arrays (arrays of arrays) for grids, like a game board or a matrix.
- Mind the length so you never read past the end.
Common mistakes
- Off-by-one errors. An array of length 5 has valid indices 0 through 4. Index 5 is out of bounds.
- Index out of bounds. Reading or writing past the end crashes or corrupts in different languages. Always check the length.
- Confusing arrays and linked lists. Reaching for an array when you need frequent middle insertions, or vice versa.
- Mutating an array while iterating it. Adding or removing elements during a loop can skip items or crash.
What to skip
- Manual size management in high-level languages. Dynamic arrays grow for you; do not reinvent that.
- Premature optimization of array operations before you have measured a real bottleneck.
- Using an array when keys would be clearer. If you look things up by name rather than position, a dictionary or map fits better.
FAQ
Why do arrays start at index 0?
The index represents an offset from the start of the array in memory. The first element is zero away from the start, so its index is 0. Most languages follow this convention.
What is the difference between an array and a list?
It depends on the language. In Python and JavaScript, lists and arrays are dynamic and grow automatically. In C or Java, an array has a fixed size, and a list is a separate growable structure.
Why is inserting into the middle of an array slow?
Because every element after the insertion point must shift one position to make room. On a large array that is a lot of moves, unlike a linked list where you just relink pointers.
What is index out of bounds?
An attempt to access a position that does not exist, like index 5 in an array of length 5. Depending on the language it crashes, throws an error, or returns nothing. Check the length first.
Where to go next
See what a variable is in 2026, what a data structure is in 2026, and what a linked list is in 2026.