六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 20|回复: 0

javascript 虚拟创建HashMap对象

[复制链接]

升级  79.33%

51

主题

51

主题

51

主题

秀才

Rank: 2

积分
169
 楼主| 发表于 2013-1-29 08:53:50 | 显示全部楼层 |阅读模式
 
/******************************************************************************* * 虚拟创建HashMap对象 * @author DT 2011-12-17 * @version 1.0 *  * 说明: * HashMap有两个Array数组构成 分别保存key、value * 场景: * 数据封装、解析 *  *******************************************************************************/function HashMap() {this.arrKey = new Array();this.arrValue = new Array();this.exists = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey[i] == strKey) {return true;}}return false;};this.length = function() {return this.arrKey.length;};this.put = function(strKey, objValue) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey[i] == strKey) {this.arrValue[i] = objValue;return;}}this.arrKey[this.arrKey.length] = strKey;this.arrValue[this.arrValue.length] = objValue;};this.get = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey[i] == strKey) {return this.arrValue[i];}}return null;};this.remove = function(strKey) {strKey = strKey.toUpperCase();for (var i = 0;i < this.arrKey.length; i++) {if (this.arrKey[i] == strKey) {this.arrKey.splice(i, 1);this.arrValue.splice(i, 1);return;}}};this.getKeys = function() {return this.arrKey;};this.getValues = function() {return this.arrValue;};} 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表