Node.js | push() function
push() is an array function from Node.js that is used to add element to the end of an array.
Syntax:
array_name.push(element)
Parameter: This function takes parameter that has to be added to the array. It can take multiple elements also.
Return type: The function returns the array after adding the element.
The program below demonstrates the working of the function:
Program 1:
function PUSH() { arr.push(2); console.log(arr); } var arr = [12, 3, 4, 6, 7, 11]; PUSH(); |
Output:
[ 12, 3, 4, 6, 7, 11, 2]
Program 2:
function addLang() { arr.push('DS','Algo','JavaScript'); console.log(arr); } var arr = ['NodeJs']; addLang(); |
Output:
[ 'NodeJs', 'DS', 'Algo', 'JavaScript' ]
Program 3:
var Lang = ['java', 'c', 'python']; console.log(Lang); // expected output: Array [ 'java', 'c', 'python' ] Lang.push('node'); console.log(Lang); // expected output: Array [ 'java', 'c', 'python', 'node' ] |
Output:
[ 'java', 'c', 'python' ] [ 'java', 'c', 'python', 'node' ]
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- PHP | Ds\Sequence push() Function
- PHP | SplDoublyLinkedList push() Function
- PHP | Ds\Vector push() Function
- PHP | Ds\Deque push() Function
- Nodejs | DNS
- Nodejs | Jimp
- Nodejs | DNS | setServers()
- Web-Socket in NodeJS
- Difference between NodeJS and AngularJS
- Dockerizing a simple Nodejs app
- Nodejs | Web Crawling using Cheerio
- Encrypting Data in NodeJS
- Cowsay in Nodejs using Requests library
- Nodejs – Connect Mysql with Node app
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.



