当前位置:编程学习 > JS >>

js实现key,value

方式一

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

}    

补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,