标签:value 分享 遍历 alert 数组遍历 png highlight each src
遍历json对象数组
1.
传统数组遍历
var data=[{"name":"zhangsan","age":12},{"name":"lisi","age":22}]; for(var i=0;i<data.length;i++) { alert(data[i].name+"--"+data[i].age); }
2.key/value map方式遍历 key-->索引 value-->Object
var data=[{"name":"zhangsan","age":12},{"name":"lisi","age":22}]; for(var key in data) { alert(data[key].name+"--"+data[key].age); }
3.$.each方式 不常用
name -->索引 value-->Object
var data=[{"name":"zhangsan","age":12},{"name":"lisi","age":22}]; $.each(data,function(name,value){ alert(name+":"+value.name+","+value.age); })
遍历json对象(没有什么实际意义 都是data.name data.age直接引用)
var data={"name":"zhangdan","age":22}; for(var key in data) { alert(data[key]); }
标签:value 分享 遍历 alert 数组遍历 png highlight each src
原文地址:http://www.cnblogs.com/lt123/p/7208915.html