js Map List 遍历使用示例 |
本文标签:js,Map,List,遍历 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;i<list.length;i++){ value = list[i] } 参考(jquery筛选数组之grep、each、inArray、map的用法及遍历json对象 ): http://sjolzy.cn/jquery-selection-and-use-of-an-array-of-grepeachinArraymap-json-object-traversal.html |