I am trying to loop through the following:
const data = {
"messages": [
{
"msgFrom": "13223821242",
"msgBody": "Hi there"
},
{
"msgFrom": "Bill",
"msgBody": "Hello!"
}
]
}
I want to retrieve msgFrom
and msgBody
I've tried:
for (const key in data) {
const obj = data[key];
for (const prop in obj) {
if(obj.hasOwnProperty(prop)){
console.log(prop + " = " + obj[prop]);
}
}
}
But the console log prints [Object]
Any ideas what im doing wrong?
console.log(obj, prop);
for..in
forArray
s.[[Prototype]]
, etc.).