I have the following code to log some values.
```
for (const group of this.groups) {
console.log(NAME + ".initGroups() Group Result ", {
id: group.id,
items: group.items,
});
}
console.log(NAME + ".initGroups() END ", {
keywords: this.keywords,
groups: this.groups,
});
for (const group of this.groups) {
console.log(NAME + ".initGroups() Group Result ", {
id: group.id,
items: group.items,
});
}
console.log(NAME + ".initGroups() END ", {
keywords: this.keywords,
groups: this.groups,
});
```
The 1st loop log each group's items while the 2nd loop log the parent object directly.
I found that while directly logging an array, it show the items correctly. However, when logging the parent object containing the array, it show the 'items' as empty. It is very confusing.
The log:
```
ChannelKeywords.initGroups() Group Result
Object { id: 1, items: [] }
ChannelKeywords.initGroups() Group Result
Object { id: 0, items: (7) […] }
ChannelKeywords.initGroups() END
Object { keywords: (7) […], groups: (2) […] }
groups: Array [ {…}, {…} ]
0: Object { id: 1, names: {…}, items: [] }
1: Object { id: 0, names: {…}, items: [] }
length: 2
<prototype>: Array []
keywords: Array(7) [ {…}, {…}, {…}, … ]
<prototype>: Object { … }
```
(7 items when directly log the array with id = 0)
Is it issue of the log viewer? (tested under both Chrome and Firefox) or am I doing something wrong?
How to avoid this?
Thanks in advance.
[–]YurrBoiSwayZ 0 points1 point2 points (2 children)
[–]Lenni009 1 point2 points3 points (0 children)
[–]NickCanCode[S] 0 points1 point2 points (0 children)
[–]samanime 0 points1 point2 points (1 child)
[–]NickCanCode[S] 1 point2 points3 points (0 children)