Array.shift()

JavaScript 1.2+ Nav4+, NES3+ Syntax

							array.shift()

Description

The shift() method deletes and returns the first element of the array. Once deleted, all the remaining elements are shifted down one spot, so the first position is filled by the element that was previously in the second position. Table 6.13 shows the return value associated with this method.

Table 6.13. Arguments and Return Values Associated with shift()
Type Item Description
Returns The first element of the array, before the elements are shifted, is returned from the method.

Example

Listing 6.55 creates an array representing people waiting for a table at a restaurant. The shift() method pulls the first name off the list and shifts all the other names up ...

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.