Mega Code Archive

 
Categories / JavaScript DHTML / Language Basics
 

Queue based on array

<html> <head> <title>FIFO</title> </head> <body> <script type="text/javascript"> var myQueue = new Array(); myQueue.push("A"); myQueue.push("B"); var ln = myQueue.push("C"); document.writeln("length is " + ln + " and array is " + myQueue + "<br />"); for (var i = 0; i < ln; i++) {    document.writeln(myQueue.shift() + "<br />"); } document.writeln("length now is " + myQueue.length + "<br /><br />"); myQueue.unshift("L"); myQueue.unshift("J"); ln = newQueue.unshift("S"); document.writeln("length is " + ln + " and array is " + newQueue + "<br />"); for (i = 0; i < ln; i++) {   document.writeln(newQueue.pop() + "<br />"); } document.writeln("new length is " + newQueue.length );i </script> </body> </html>