Skip to content
Related Articles

Related Articles

Improve Article

Node.js | shift() function

  • Last Updated : 30 Aug, 2019

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

Syntax:

array_name.shift()

Parameter: This function does not takes any parameter.

Return type: The function returns the array after deleting the element.

The program below demonstrates the working of the function:



Program 1:




function shiftDemo()
{
  arr.shift();
  console.log(arr);
}
var arr=[17, 55, 87, 49, 78];
shiftDemo();

Output:

[ 55, 87, 49, 78 ]

Program 2:




function shiftDemo()
{
  arr.shift();
  console.log(arr);
}
var arr=['a', 'b'];
shiftDemo();

Output:

[ 'b' ]

Program 3:




let Lang = ["Python", "C", "Java", "JavaScript"];
while ((i = Lang.shift()) !== undefined) {
    Lang.shift();
}
console.log(Lang);

Output:

[]



My Personal Notes arrow_drop_up
Recommended Articles
Page :