如何在JavaScript中打印对象数组的内容?

时间:2019-05-16 07:34:33

标签: javascript arrays object

我使用以下代码打印所有人的信息:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var txt = "";
var person = [{fname:"John", lname:"Doe", age:25},
              {fname:"Hasan", lname:"Doe", age:26}]; 
var x;
for (x in person) {
  txt += person[x] + " ";
}
document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

但是结果是:

  

[对象对象] [对象对象]

为什么会这样?

0 个答案:

没有答案