//自定义键值对对象
function Dictionary() {
this.data = new Array();
this.put = function (key, value) {
this.data[key] = value;
};
this.get = function (key) {
return this.data[key];
};
this.remove = function (key) {
this.data[key] = null;
};
this.isEmpty = function () {
return this.data.length == 0;
};
this.size = function () {
return this.data.length;
};
}<pre name="code" class="javascript">//然后就可以通过
var typeArr = new Dictionary();
typeArr.put(1, "1"); //存
typeArr.get(1);//=1 取
typeArr.remove(1);//删除指定元素
typeArr.isEmpty();//删除所有元素
typeArr.size();//获取长度
javscript中自定义键值对(Dictionary)
最新推荐文章于 2022-04-03 17:54:30 发布