<script>
function Map() {
var struct = function(key, value) {
this.key = key;
this.value = value;
}
var put = function(key, value){
for (var i = 0; i < this.arr.length; i++) {
if ( this.arr[i].key === key ) {
this.arr[i].value = value;
return;
}
}
this.arr[this.arr.length] = new struct(key, value);
}
var get = function(key) {
for (var i = 0; i < this.arr.length; i++) {
if ( this.arr[i].key === key ) {
return this.arr[i].value;
}
}
return null;
}
var remove = function(key) {
var v;
for (var i = 0; i < this.arr.length; i++) {
v = this.arr.pop();
if ( v.key === key ) {
continue;
}
this.arr.unshift(v);
}
}
var size = function() {
return this.arr.length;
}
var isEmpty = function() {
return this.arr.length <= 0;
}
this.arr = new Array();
this.get = get;
this.put = put;
this.remove = remove;
this.size = size;
this.isEmpty = isEmpty;
}
</script>
<script>
var map = new Map();
map.put("name", "1");
map.put("firstName", "2");
map.put("lastName", "3");
map.put("sex", "4");
map.put("email", "5");
map.put("industry","6");
map.put("company", "7");
map.put("post", "8");
map.put("address", "9");
map.put("phone", "10");
map.put("phone_2","11");
map.put("fax","12");
map.put("qq","13");
map.put("msn","14");
map.put("skype","15");
map.put("other","16");
map.put("other_2","17");
map.put("other_3","18");
map.put("other_4","19");
map.put("other_5","20");
// alert("map的大小为:" + map.size()) ;
// map.remove("other_2");
// alert("map移除一个元素后的大小为:" + map.size());
/* alert("key为re的map中存储的对象为:" + map.get("re"));
map.remove("re");
alert("移除key为re的对象后,获取key为re的map中存储的对象为:" + map.get("re"));
alert("map移除一个元素后的大小为:" + map.size());
alert("map是否是一个空map:" + map.isEmpty()); */
</script>