HOW TO SHIFT AND UNSHIFT USING JAVASCRIPT?

Dependra Pathak

Total Post:77

Points:385
Posted by  Dependra Pathak
 1562  View(s)
Ratings:
Rate this:
  1. Dependra Pathak

    Post:77

    Points:385
    How to shift and unshift using JavaScript?

    for example:

    <script type="text/javascript">
    var numbers = ["one", "two", "three", "four"];
    numbers.unshift("zero");
    document.write(" "+numbers.shift());
    document.write(" "+numbers.shift());
    document.write(" "+numbers.shift());
    </script>

    output:

    zero one two
    shift, unshift, push, and pop may be used on the same array in JavaScript. Queues are easily implemented using combinations.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!