Which array method adds an element to the beginning?
Answer
unshift()
Answer
unshift()
The array method that adds an element to the beginning is `unshift()`. It inserts one or more values at index 0, shifts existing elements to higher indexes, and returns the array’s new length.
For example, `[2, 3].unshift(1)` changes the array to `[1, 2, 3]` and returns `3`. Passing several values at once, such as `unshift(1, 2)`, keeps those values in the order supplied. Repeated one-at-a-time calls can produce a different order because each new value is inserted before the previous one.
The common mix-up is with `push()`, which adds elements at the end and returns the new length. `shift()` removes the first element, while `splice()` can insert or remove elements at arbitrary positions but is not the dedicated front-insertion method. `unshift()` also works on array-like objects that have a `length` property and integer-indexed elements.
Source: Wikipedia · fact-checked Aug. 2026