1.在数组中使用 var str = ["a", "b", "c"]; for (var item in str) { //alert(item); 下标 alert(str[item]); }
2.在JSON数据中使用 var str = '{"name":"Job","age":"22","post":"C#开发","hobit":["游泳","跳水"],"travel":{"day":"12月","where":"China","with":["Dad","Mon"]}}'; str = JSON.parse(str); //将JSON字符串转为JavaScript对象 for (var item in str) { //alert(item); 属性名 //alert(str[item]); 属性值 //alert(str.travel.day); 属性值 } for (var item in str.travel) { //alert(item); alert(str.travel[item]); }