push definition and usage
Thepush() method adds one or more elements to the end of the array and returns the new length.
Grammar
arrayObject.push(newelement1,newelement2,....,newelementX)
Parameter Description
newelement1 required. The first element to be added to the array.
newelement2 Optional. The second element to be added to the array.
newelementX Optional. Multiple elements can be added.
Return value
Add the specified value to the new length of the array.
Description
The push() method adds its parameters sequentially to the end of arrayObject. It directly modifies the arrayObject instead of creating a new array. The push() method and pop() method use the first-in-last-pop function provided by the array.
Tips and Notes
Note: This method will change the length of the array.
Tip: To add one or more elements to the beginning of an array, use the unshift() method.
Example
In this example we will create an array and change its length by adding an element:
Output:
George,John,Thomas
4
George,John,Thomas,James
A usage on the Internet:
Note: You need to load jquery.js first before using it