I am Learning JavaScript and I would like to know why I am not able to print objects within for in and for of loops whereas I can if not inside a loop (see below):
let arr = [{abc: '123'}, {xyz: '321'}];
let obj = {obj1:{abc: '123'}, obj2:{xyz: '321'}};
for(let x of arr)
{
console.log(`${x}`);
}
for(let x of arr)
{
console.log(`${x}`);
}
console.log(arr[0]); // this works
console.log(obj.obj1); // this works
Could someone explain why this is please, it keeps printing [object object] and I have no idea why. I thought it should print the entire object and its contents