JavaScript
JavaScript 对象
循环遍历对象的属性
源代码:
点击运行 »
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p> <button onclick="myFunction()">点击这里</button> <p id="demo"></p> <script> function myFunction() { var x; var txt = ""; var person = { fname: "Bill", lname: "Gates", age: 56 }; for (x in person) { txt = txt + person[x]; } document.getElementById("demo").innerHTML = txt; } </script>
运行结果:
点击运行 »