Basic JavaScript Question:
Download Questions PDF

How to shift and unshift using JavaScript?


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

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

Download JavaScript Interview Questions And Answers PDF

Previous QuestionNext Question
How to make a array as a stack using JavaScript? How to create an object using JavaScript?