Node.js | unshift() function
unshift() is an array function from Node.js that is used to insert element to the front of an array.
Syntax:
array_name.unshift(element)
Parameter: This function takes parameter that has to be added to the array. It can take multiple elements also as parameter.
Return type: The function returns the array after adding the element.
The program below demonstrates the working of the function:
Program 1:
function unshiftDemo() { var element = arr.unshift(12); console.log(arr); } var arr=[1, 5, 7, 9, 78]; unshiftDemo(); |
Output:
[12,1,5,7,9,78]
Program 2:
function addLang() { var element = arr.unshift("Node.js","php"); console.log(arr); } var arr=[ "C", "Java", "JavaScript", "Python" ]; addLang(); |
Output:
[ 'Node.js', 'php', 'C', 'Java', 'JavaScript', 'Python' ]
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- PHP | SplDoublyLinkedList unshift() Function
- PHP | Ds\Vector unshift() Function
- PHP | Ds\Sequence unshift() Function
- PHP | Ds\Deque unshift() Function
- Nodejs | DNS
- Nodejs | Jimp
- Nodejs | DNS | setServers()
- Web-Socket in NodeJS
- Nodejs | Web Crawling using Cheerio
- Dockerizing a simple Nodejs app
- Difference between NodeJS and AngularJS
- Encrypting Data in NodeJS
- Signup Form Using Nodejs and MongoDB
- NodeJs - Handling invalid routes
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.


