Shifting Elements in JS

PHOTO EMBED

Thu Dec 03 2020 04:27:34 GMT+0000 (Coordinated Universal Time)

Saved by @Amna #javascript

<!DOCTYPE html>
<html>
<body>
​
<h2>JavaScript Array Methods</h2> 
​
<h2>shift()</h2>
​
<p>The shift() method removes the first element of an array (and "shifts" all other elements to the left):</p>
​
<p id="demo1"></p>
<p id="demo2"></p>
​
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = fruits;
fruits.shift();
document.getElementById("demo2").innerHTML = fruits;
</script>
​
</body>
</html>
​
content_copyCOPY

The shift() method removes the first array element and "shifts" all other elements to a lower index.

https://www.w3schools.com/js/tryit.asp?filename