Call Us : +91-8376986802 (Viber, WhatsApp)

How to shift and unshift using JavaScript?



var numbers = [“one”, “two”, “three”, “four”];
numbers.unshift(“zero”);
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. Queues are easily implemented using combinations.

Leave a Reply