HOW TO SHIFT AND UNSHIFT USING JAVASCRIPT?

Chris Anderson

Total Post:197

Points:985
Posted by  Chris Anderson
 2485  View(s)
Ratings:
Rate this:
  1. Chris Anderson

    Post:197

    Points:985
    How to shift and unshift using JavaScript?

    <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>
    This produces
    zero one two
    shift, unshift, push, and pop may be used on the same array. Queues are easily implemented using combinations.

Answer

NEWSLETTER

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