home / experts / javascript / column59 |
|
LIFO OperationsInternet Explorer 5.5 provides four new methods for the Array object: The Stack is a known abstract type in computer science. No matter how you implement the Stack, it always supports the basic operations of push and pop. The push operation adds elements to the top of the stack. Here is the method to be declared as a prototype of the
The first line of the function sets the position of the new element. The length of the array is
When the browser is a pre-5.5 version, we need to extend the Array's prototype with the new
We do nothing when the browser is IE 5.5 or higher. For other browsers or lower versions, we assign the home-brewed
You can find the code itself in a later page of this column. Go ahead and run this script now. You should get a window like this:
The
The first line sets the last element of the array, situated at index When the browser is a pre-5.5 version, we need to extend the Array's prototype with the new
We do nothing when the browser is IE 5.5 or higher. For other browsers or lower versions, we assign the home-brewed
You can find the code itself in a later page of this column. Go ahead and run this script now. You should get the following window:
Next: How to shift and unshift array elements |
Produced by Yehuda Shiran and Tomer Shiran
Created: March 14, 2000
Revised: April 26, 2000
URL: http://www.webreference.com/js/column59/4.html