Skip to content
Related Articles

Related Articles

Node.js unshift() function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 14 Oct, 2021

unshift() is an array function from Node.js that is used to insert element to the front of an array.



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);
var arr=[1, 5, 7, 9, 78];



Program 2:

function addLang()
  var element = arr.unshift("Node.js","php");
var arr=[ "C", "Java", "JavaScript", "Python" ];


[ 'Node.js', 'php', 'C', 'Java', 'JavaScript', 'Python' ]

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!