Array shift() Method - Javascript Array

Javascript examples for Array:shift

Description

The shift() method removes the first item of an array, and returns that item.

Parameters

None

Return Value:

the removed array item.

The following code shows how to Remove the first item of an array:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
var fruits = ["a","b","c","d","e"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {/*  w w  w. j  av  a  2s . c  o m*/
    fruits.shift();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>

Related Tutorials