for in 遍历json
程序员文章站
2024-01-30 20:17:52
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>for in 遍历</title>
</head>
<body>
</body>
</html>
<script type="text/javascript">
var arr={
'name':['a','b','c'], //json数据
'age':[1,2,3]
};
for(var attr in arr){ //for in循环遍历
for(var i=0;i<arr[attr].length;i++){
console.log(arr[attr][i]);//abc123
}
}
</script>