当前位置: 代码迷 >> JavaScript >> js兑现key,value
  详细解决方案

js兑现key,value

热度:412   发布时间:2012-10-29 10:03:53.0
js实现key,value
方式一

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


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]}   
} 



  相关解决方案