Maison  >  Article  >  interface Web  >  js Map List 遍历使用示例_javascript技巧

js Map List 遍历使用示例_javascript技巧

WBOY
WBOYoriginal
2016-05-16 17:29:191686parcourir

Map (exMap:{"name":"abc","sex",'male'}):
在不知道key的情况下遍历map:
网上说过这种方法:

复制代码 代码如下:

for(var key in exMap){
Console.write("key:"+key+";value:"+exMap[key]);//经我考证,the key is undefined.So the method is not right.
}

另外一种方法(Good):
复制代码 代码如下:

$.each(exMap,function(key,value){
Console.wiite("key:"+key+";value:"+value);
});

在知道的key的情况下遍历map自然就跟数组一样的访问罗,这里就不说了。
List访问很简单:
复制代码 代码如下:

for(var i =0;ivalue = list[i]
}

参考(jquery筛选数组之grep、each、inArray、map的用法及遍历json对象 ):
http://sjolzy.cn/jquery-selection-and-use-of-an-array-of-grepeachinArraymap-json-object-traversal.html
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn