JavaScript


push() JavaScript Array method tutorials
-
JavaScript array push() method appends the given element(s) in the last of the array and returns the length of the new array.
-
This method changes the length of an array.
-
To add new elements at the beginning of an array use unshift() method.
Syntax:
array.push (element1, element2,. . . ., elementN)
Note: The new item(s) will be added at the end of the array. This method changes the length of the array.
-
Browser Support: The push() method is supported in all major browsers, like Internet Explorer, Firefox, Chrome, Safari.
Example: javascript push() method with an array.
Output:
Original num Array = 2,4,6
Original elements in num Array = 3
New num Array after push = 2,4,6,8
Numbers of elements in num Array after 1st push = 4
New num Array after 2nd push = 2,4,6,8,10
Numbers of elements in num Array after 2nd push = 5
Example:The following example shows how to use JavaScript push() method with an array.
Output: