我正在尝试理解以下 javascript 代码片段
<!DOCTYPE html>
<html>
<body>
<p>Click the button to loop through the properties of an object named "person".</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script type="text/javascript">
function myFunction()
{
var x;
var txt="";
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
txt=txt + person[x];
}
document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html>
我对这条线有点困惑
for (x in person)
{
txt=txt + person[x];
}
正如我猜测的那样,它是一个关联数组,具有键-> 值关系,最终结果不应该像这样打印吗?
fname:"John",lname:"Doe",age:25
? 非常感谢