shift() - JavaScript Tutorial

shift()

BLUF: This tutorial on shift() provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: shift()

Understanding shift() is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The shift method in JavaScript arrays eliminates the initial element from the specified array and provides that element as a return value. This operation modifies the length of the original array.

Syntax

The syntax for the shift method is illustrated as follows:

Example

array. shift()

Return

The first element of an array.

JavaScript Array shift method example

Let’s examine a scenario in which we will eliminate and retrieve the first element from an array.

Example

Example

<script>

var arr=["AngularJS","Node.js","JQuery"];

var result=arr.shift();

document.writeln(result);

</script>

Output:

Output

AngularJS

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience