运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <p>Looping through arrays inside arrays.</p> <p id="demo"></p> <script> let x = ""; const myObj = { "name":"John", "age":30, "cars": [ {"name":"Ford", "models":["Fiesta", "Focus", "Mustang"]}, {"name":"BMW", "models":["320", "X3", "X5"]}, {"name":"Fiat", "models":["500", "Panda"] } ] } for (let i in myObj.cars) { x += "<h2>" + myObj.cars[i].name + "</h2>"; for (let j in myObj.cars[i].models) { x += myObj.cars[i].models[j] + "<br>"; } } document.getElementById("demo").innerHTML = x; </script> </body> </html>