Queue based on array : Array « Language Basics « JavaScript DHTML

Queue based on array


<script type="text/javascript">
var myQueue = new Array();
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 />");
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



Related examples in the same category

1.Demo all methods in Array
2.Assing array value inside function
3.Simple Array Demo
4.Array loop, find:Control array : Two dimension array
5.Reversing, Sorting, and Concatenating an Array
6.Custom Numeric Comparison for the Array.Sort Method
7.Case-Insensitive Comparison for the Array.Sort Method
8.Iterating Through a Sparse Array
9.Using Functions to Iterate Through an Array
10.Reading and Writing Array Elements
11.Array with a numeric parameter and assign data to it
12.A string array
13.Array - properties and methods:length, join, reverse, push,pop,shift
14.Array - sort()
15.Array - concat and slice
16.Array - splice
17.Methods and Properties of the Array Object
18.Displaying the Contents of an Array
19.Using the Array.join() Method
20.Using JavaScript Arrays
21.Extending the Length of an Array
22.An Array within an Array
23.Using the Methods of the Array object
24.Array.sort() Possibilities
25.Array.reverse() Method
26. Array Concatenation
27.A Looping Array Lookup
28.A Simple Parallel Array Lookup
29.Adding a prototype Property
30.Two-Dimensional Array Work Around
31.Array definition and iteration
32.Reference an Array by index
33.URL Array
34.Array Utility functions
35.Dynamic array
36.Use for loop to display elements in an array
37.A string array variable