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
  • 497
  • 6
  • 23
Hasani
  • 3,543
  • 14
  • 65
  • 125

0 Answers0