Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - shift()

https://www.w3schools.com/jsref/jsref_obj_array.asp

Shifting is equivalent to popping, working on the first element instead of the last. The shift() method removes the first array element and "shifts" all other elements to a lower index. It DOES reassign new indexes.


let fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("before").innerHTML = fruits.join("-");

fruits.shift();

document.getElementById("after").innerHTML = fruits.join("-");

let output = "";
for (var i = 0; i < fruits.length; i++) { output +="The index is " + i + "<br />" ; }
document.getElementById("demo2").innerHTML=output;

results: