Home > DeveloperSection > Interviews > How to shift and unshift using JavaScript?

Posted on    October-17-2011 12:12 AM

 JavaScript JavaScript 
Ratings:
 1 Answer(s)
  2220  View(s)
Rate this:

Chris Anderson
Chris Anderson

Total Post:197

Points:985
Posted on    October-17-2011 12:00 AM

<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.


Don't want to miss updates? Please click the below button!

Follow MindStick