Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js shift() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Syntax:

array_name.shift()

Parameter: This function does not take any parameter. 

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

The program below demonstrates the working of the function: 

Program 1: 

javascript




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


Output:

[ 55, 87, 49, 78 ]

Program 2: 

javascript




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


Output:

[ 'b' ]

Program 3: 

javascript




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


Output:

[]

My Personal Notes arrow_drop_up
Last Updated : 30 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials