|
||
Hashtable.prototype.hash = null;
Hashtable.prototype.keys = null;
Hashtable.prototype.location = null;
function Hashtable(){
this.hash = new Array();
this.keys = new Array();
this.location = 0;
}
Hashtable.prototype.get = function (key)
return this.hash[key];
}
Hashtable.prototype.put = function (key, value){
if (value == null)
return null;
if (this.hash[key] == null)
this.keys[this.keys.length] = key;
this.hash[key] = value;
}
//declare an instance
var items = new Hashtable();
//add 3 values to the hash
items.put("key1", "value1");
items.put("key2", "value2");
items.put("key3", "value3");
//just show that all works well
alert(items.get("key2"));
//start iterating the hash
//Just to be on the safe side (maybe someone has used it before?)
items.moveFirst();
while (tems.next()){ //While we have more elements
//print the key and the value
alert (items.getKey() + " = " + items.getValue());
}