RSRobince Studio

Arrays

An array is an ordered list of values. You read any item by its index (counting from 0) instantly, and you can add or remove items at the end quickly with push and pop.

const items = []
items.push(1)
items.push(2)
const last = items.pop()  // 2

Reading arr[i] and changing the end are fast. Adding or removing at the front is slower, because every other item has to shift along.

Try it yourself

Loading editor…

Reading by index is O(1) — instant whatever the size. Searching for a value whose position you do not know means checking items one by one, which is O(n).