js 遍历json对象

//方法一:
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}];  
for(var o in data){
    console.log("text:"+data[o].name+" value:"+data[o].age );  
}  
// 方法二:
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}];  
for(var i=0; i<data.length; i++){
    console.log("text:"+data[i].name+" value:"+data[i].age );  
}  

 

posted @ 2016-05-28 16:35  cloudshadow  阅读(2565)  评论(0编辑  收藏  举报