One, the stack data structure, LIFO (Last-in-first-out, LIFO) of the database structures;
The push () method can receive any number of arguments, add them individually to the end of the array, and return the length of the modified array;
The Pop () method removes the last item from the end of the array, reduces the length value of the array, and then returns the removed item;
1 varcolors =NewArray ();// Create an array2 varCount = Colors.push ("Red", "green");// push in two items3alert (count);//24 5Count = Colors.push ("Black");// push into another item6alert (count);//37 8 varitem = Colors.pop ();// get the last one9alert (item);//"BLACK"Tenalert (colors.length);//2
Second, the queue data structure, FIFO (First-in-first-out, first-out);
Shift () method, which can move the first item in the array and return the item, while reducing the length of the arrays by 1;
var New Array (); var count = Colors.push ("Red", "green"); alert (count); // 2 = Colors.push ("BLACK"); alert (count); // 3 var item = Colors.shift (); // get the first alert (item); // Redalert (colors.length); // 2
Stack method and queue method for array