简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>简单教程( www.twle.cn )</title> </head> <body> <p>循环内嵌数组</p> <p id="demo"></p> <script> var myObj, i, j, x = ""; myObj = { "name":"公司", "num":4, "sites": [ { "name":"腾讯", "info":[ "腾讯QQ", "微信", "腾讯企业邮箱" ] }, { "name":"百度", "info":[ "百度搜索", "百度地图", "百度百科" ] }, { "name":"简单教程", "info":[ "简单教程", "简单编程" ] }, { "name":"阿里巴巴", "info":[ "淘宝", "天猫","支付宝" ] } ] } for (i in myObj.sites) { x += "<h1>" + myObj.sites[i].name + "</h1>"; for (j in myObj.sites[i].info) { x += myObj.sites[i].info[j] + "<br>"; } } document.getElementById("demo").innerHTML = x; </script> </body> </html>
运行结果: