arr.push() function is used to push one or more values into the array. This function changes the length of the array by the number of elements added to the array. The syntax of the function is as follows:
arr.push(element1[, ...[, elementN]])
Arguments This function contains as many numbers of arguments as the number of elements to be inserted into the array.
Return value This function returns the new length of the array after inserting the arguments into the array.
Examples for the above function are provided below:
var arr = [34, 234, 567, 4]; print(arr.push(23,45,56)); print(arr);
In this example the function push() adds the numbers to the end of the array.
var arr = [34, 234, 567, 4]; print(arr.push('jacob',true,23.45)); print(arr);
In this example the function push() adds the objects to the end of the array.
Codes for the above function are provided below:
- p5.js | Push Operation on Stack
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.