W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 在循环中显示对象</h1> <p>可以在循环中收集对象的属性</p> <p id="demo"></p> <script> const person = { name: "Bill", age: 19, city: "Seattle" }; let txt = ""; for (let x in person) { txt += person[x] + " "; }; document.getElementById("demo").innerHTML = txt; </script> </body> </html>