Array.unshift()
JavaScript 1.2+ Nav4+, NES3+ Syntax
array.unshift(arg1,…argN)
Description
The unshift() method adds the arguments listed in the parameter list to the front of the array as new elements. Existing elements are shifted up to allow room for the new elements. Table 6.18 lists the arguments and return values associated with this method.
Type | Item | Description |
---|---|---|
Arguments | arg1,…argN | Elements to be added to the array |
Returns | The length of the array after adding the new elements. |
Example
Listing 6.61 creates an array of school grades. Two new grades, 100 and 93 are added to the front of the array using the unshift() method. After the unshift() method has executed, ...
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.