How to use the shift in JavaScript

In this article we will discuss about How to use the shift() method in JavaScript.
  • 2087

This method is used to remove the first element of the Array Object in JavaScript and returns that removed element. This is the most popular method of Array Object in JavaScript. The syntax of this Method is as follows:

Syntax:

array.shift();

This method returns the single of value which was removed by it.

JavaScript Code:

<html>

<head>

    <title>JavaScript Array shift Method</title>

</head>

<body>

    <script type="text/javascript">

        var number = [101, 4, 5, 6].shift();

        document.write("Removed element is : " + number);

    </script>

</body>

</html>

Output:

myoutput4.jpg

Ask Your Question 

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

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.