1

I use the following code to print information of all persons:

<!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>

But the result is:

[object Object] [object Object]

Why does this happen?

Alator
  • 487
  • 7
  • 22
user3486308
  • 2,166
  • 3
  • 32
  • 62

0 Answers0