<html>
<body>
<p id="demo"></p>
<script>
var data = [
{'name': 'person1','location': 'NY'},
{'name': 'person2','location': 'NY'},
{'name': 'person3','location': 'CA'}
];
var text="";
for (var i=0; i<=2; i++) {
text+='<div>'+data[i]+'</div>';
}
data.forEach(info => {
document.getElementById('demo').innerHTML = text;
});
</script>
</body>
</html>
Right now it's printing [object Object]
. How can I show the content of the object? Is my approach of using forEach method wrong?