Array.unshift
Array.unshift
Function
Insert one or more elements into the beginning of the array.
Syntax
array.unshift(value1, value2, ...)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| valueN | Any | No | None | The element to insert. |
Return value
| Type | Description |
|---|---|
| Array | Returns the original array object. |
Example
items = [2, 3] result = items.unshift(1) // Output: [1,2,3] print result
Notes
- This method will modify the original array.