源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <body> <p>循環內嵌數組:</p> <p id="demo"></p> <script> var myObj, i, j, x = ""; myObj = { "name":"網站", "num":3, "sites": [ { "name":"Google", "info":[ "Android", "Google 搜索", "Google 翻譯" ] }, { "name":"Runoob", "info":[ "教程", "工具", "微信" ] }, { "name":"Taobao", "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>
運行結果