js 遍历json对象

时间:2022-06-08 19:17:16
//方法一:
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 );  
}