What is an array?
An array is an ordered collection of values stored in contiguous slots.
Each slot has an index starting at 0, so you can read or write any position
directly — arr[i] — without walking past everything before it.
- Index
- The address of a slot, counting from
0 - Element
- The value stored at that index
- Contiguous
- Slots sit next to each other in memory, in order
See it as slots
Picture a row of numbered mailboxes. Index 0 is the first box, 1 the next,
and so on. Because the boxes sit in a straight line, knowing the index is enough —
you jump straight to that box.
Watch the pointer move. Sequential steps walk neighbor to neighbor. Then it jumps to a later index in one hop — the same cost as opening the first box.
Same cost for any index. Contiguous slots make that possible.
Types of arrays
Not every array looks the same. In interviews and real systems you usually classify arrays in two ways: how their size is managed, and how many dimensions they use.
Static arrays keep a fixed length. Dynamic arrays can grow. One-dimensional arrays are a single row of values. Multi-dimensional arrays nest rows into tables or deeper grids.
Size answers “can it grow?” Shape answers “how is it laid out?”
How it is stored in memory
In TypeScript, when declaring an array creates a pointer in stack memory and that pointer is an address to heap memory where actual array values are stored.
Start here. Each step highlights the TypeScript below.
Operations
Think of the array as a row of numbered boxes. Here are the everyday things you can do with those boxes — tap Next on each demo to watch it happen. For every built-in method and copy-paste snippets, open the Functions tab.
Access
Peek inside one box by its number. You do not walk past the others — you open that box directly.
Open box 0 — you go straight there.
Update
Swap what sits in a box. Pick the number, put the new value in, leave the rest alone.
Box 1 currently holds 3.
Search
Looking for a value? Start at the first box and walk along until you find it — or reach the end empty-handed.
Looking for 9. Box 0 has 7 — keep walking.
Insert at end
Add a new box at the end of the row. Nobody else has to move over.
Four boxes are full. Add one more at the end.
Insert at index
Squeeze a new value into the middle. Everyone after that spot slides one box to the right to make room.
Want 5 in box 1. Everyone after must scoot right.
Delete at end
Take away the last box. The rest of the row stays put.
Take away the last box only.
Delete at index
Pull a box out of the middle. Everyone after it slides left so there is no empty hole in the row.
Remove box 1 (the 3). Close the gap.
Traverse
Walk the whole row from first box to last. Useful when you need to see or use every value once.
Visit box 0.