DEVFYI - Developer Resource - FYI

How to shift and unshift using JavaScript?

JavaScript Interview Questions and Answers


(Continued from previous question...)

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

(Continued on next question...)

Other Interview Questions