Node.js | shift() function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[ 55, 87, 49, 78 ]

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[ 'b' ]

Program 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[]


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.