Layout Options

  • Fixed Header
    Makes the header top fixed, always visible!
  • Fixed Sidebar
    Makes the sidebar left fixed, always visible!
Array Shift

Description

The shift() method removes the first element of an array, and returns that element.

This method has the form:

Array.shift()

Examples

The following example shows the basic use of this method.

<script>
var cols = [ "Red", "Green", "Blue" ];
document.write(cols.shift());
</script>

This produces the following result:

Browser Support

Firefox IE Chrome Opera Safari

Description

The unshift() method adds new elements to the beginning of an array, and returns the new length.

This method has the form:

Array.unshift(e1,e2,...,eX)
Parameter Description
e1,e2,...,eX (required) The element(s) to add to the beginning of the array

Note: This method changes the original array.

Examples

The following example shows the basic use of this method.

<script>
var cols = [ "Red", "Green", "Blue" ];
document.write(cols.unshift("Yellow"));
document.write("<br />");
document.write(cols);
</script>

This produces the following result:

Browser Support

Firefox IE Chrome Opera Safari