The push() method adds zero or more elements to the end of the array.
Example
push() Syntax
The syntax of the push() method is:
arr.push(element1, element2, ..., elementN)
Here, arr is an array.
push() Parameters
The push() method takes in an arbitrary number of elements to add to the array.
push() Return Value
- Returns the new (after appending the arguments) length of the array upon which the method was called.
Notes:
- This method changes the original array and its length.
- To add elements to the beginning of an array, use the JavaScript Array unshift() method.
Example: Using push() method
Output
[ 'JavaScript', 'Python', 'Java', 'Lua', 'C++' ] 5 [ 12, 21, 35, 44, 10, 1.6 ] 6
Recommended Readings: