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

Posted on    March-18-2011 12:00 AM

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

Dependra Pathak
Dependra Pathak

Total Post:77

Points:385
Posted on    March-18-2011 12:00 AM

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.


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

Follow MindStick