I get an object from a function after some process like this :
const mainObj = await processObj()
the object structure like :
{
'Test 1': {
Nested1: 'value 1',
Nested2: 'value 2',
Nested3: 'value 3',
Nested4: 'value 4',
Nested5: 'value 5'
},
'Test 2': {
Nested1: 'value 1',
Nested2: 'value 2',
Nested3: 'value 3',
Nested4: 'value 4',
Nested5: 'value 5'
},
'Test 3': {
Nested1: 'value 1',
Nested2: 'value 2',
Nested3: 'value 3',
Nested4: 'value 4',
Nested5: 'value 5'
}
}
'Test X' and 'Nested X' are dynamic property names, I want to loop the object and try to update each 'value X' of each nested object.
I can acccess the values but I cannot update, the following does show the result :
for (const x in mainObj) {
for (const y in mainObj[x]) {
const count = await dbquery(x,y)
console.log(`${x} ${y} ${count}`)
}
}
But when I try to update, it doesn't work :
for (const x in mainObj) {
for (const y in mainObj[x]) {
const count = await dbquery(x,y)
mainObj[x][y] = count
}
}
When I console.log(mainObj), I get the last iteration results in all nested objects.
I think It's a reference issue, and need to use Object.Assign() but I don't have ideas how