An array gives you four basic operations. Two of them are effectively free, and two of them get more expensive as the array grows. Knowing which is which is most of what separates a fast solution from a slow one.
Reading ages[3] or assigning ages[3] = 22 takes the same amount of time regardless of whether the array holds ten values or ten million. The machine computes where slot 3 lives and goes straight there — it never looks at the other slots.
const third = ages[3]; // read — instantages[3] = 22; // write — instantWe write this cost as O(1), meaning the time does not depend on the size of the array. This is the array's defining superpower, and the next lesson shows exactly how it is achieved.
Now the expensive pair. An array is one unbroken run of slots with no gaps, and that rule has to hold after your change as well as before it. So inserting into the middle means making room.
To insert at index 2, every element from index 2 onward has to shift one slot to the right — and the work grows with how many elements sit to the right of your insertion point. Deleting has the mirror problem: remove a middle element and everything after it must shift left to close the gap.
In the worst case you touch nearly every element, so insertion and deletion cost O(N), where N is the number of elements. Note the exception worth remembering: inserting or deleting at the end shifts nothing, so it is O(1).
If you know the index, finding a value is instant. If you only know the value, you have no choice but to look — checking slot 0, then 1, then 2, until you find it or run out of array.
That is O(N) in the worst case. There is a large exception: if the array is sorted, binary search finds any value in O(log N), which is dramatically faster. You'll see binary search at work in Find Peak Element, later in this course.
Read that list as a description of what arrays are for. They are superb when you mostly read by index and append at the end, and a poor fit when you are constantly inserting into the middle. When a problem is dominated by middle insertions, that is the signal to reach for a linked list instead — which is exactly where this course goes next.