js实现key,value
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 12:39 点击:次
方式一
Java代码
var hashMap = {};
hashMap['key1'] = 'value1';
hashMap['key2'] = 'value2';
hashMap['key3'] = 'value3';
hashMap['key4'] = 'value4';
hashMap['key5'] = 'value5';
hashMap['key6'] = 'value6';
if( 'key2' in hashMap)
{
alert('existance');
}
for(value in hashMap)
{
alert(value);
}
方式2
Js代码
var hashMap = {
Set : function(key,value){this[key] = value},
Get : function(key){return this[key]},
Contains : function(key){return this.Get(key) == null?false:true},
Remove : function(key){delete this[key]}
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>