All Objects
Array Object
Pop
Push
Shift
METHOD: Array::unshift
Array.
unshift
(element1,..., elementN)
The
unshift
method adds one or more elements to the beginning of an array and returns the new length. The following code first creates an array called 'trees' and then uses the
unshift
method to add two new elements to the beginning of it, returning the new length of the array. Finally, the third line of code displays all the elements of the altered array:
Code:
trees = ["beech", "maple", "sycamore"]
document.write(trees.unshift("oak", "ash"))
document.write("<BR>" + trees)
Output:
5
oak,ash,beech,maple,sycamore
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information