How to use Array pop in JavaScript

In this article we will discuss about How to use Array pop() Method in JavaScript.
  • 2123

The pop() method is most popular method of an Array object in JavaScript. This method is used to remove the last inserted element in the Array and also returns this removed element. Lets have a look on the syntax of this method.

Syntax:

array.pop();

It will remove the last inserted element from the Array.

JavaScript Code:

<html>

<head>

    <title>JavaScript Array pop Method</title>

</head>

<body>

    <script type="text/javascript">

        var values = [5, 8, 1];

 

        var removelement = values.pop();

        document.write("element is : " + removelement);

 

        var removelement = values.pop();

        document.write("<br />element is : " + removelement);

    </script>

</body>

</html>

Output:

myoutput2.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.