Array pop() Method - Javascript Array

Javascript examples for Array:pop

Description

The pop() method removes and returns the last element of an array.

This method changes the length of an array.

Parameters

None

Return Value:

removed array item.

The following code shows how to Remove the last element 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 a  v  a  2  s . c om
    fruits.pop();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>

Related Tutorials