js实现key,value
程序员文章站
2022-05-07 21:18:15
方式一
Java代码
var hashMap = {};
 ...
方式一
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]}
}