Array.shift() : Shift « Array « JavaScript Tutorial






The shift() method deletes and returns the first element of the array.

Once deleted, all the remaining elements are shifted down one spot.

The first position is filled by the element that was previously in the second position.

<html>
    <script language="JavaScript">
    <!--
    lineOfPeople = new Array(""A","B","C");
    personToSeat = lineOfPeople.shift();

    document.write("Please seat ",personToSeat,"<br>");
    document.write("People waiting for a seat: ",lineOfPeople.join(', '));

    -->
    </script>








11.26.Shift
11.26.1.Array.shift()
11.26.2.Use Array.shift to remove the first element from an array
11.26.3.Using shift method from zArray Library