I'm trying to dynamically add object values using a type
variable.
Here is a working example without using a type
variable:
let test = {
'details': {
'address': {
'line1': '13 test st'
}
}
}
test['details']['address']['line1'] = '18 test st'
console.log('test', test)
The test
variable successfully has a new line1
of '18 test st'
. However, I want to be able to use a type
variable, which fails:
let type = `['details']['address']['line1']`
`${test}${type}` = '20 test st'
How can this be achieved? I know my syntax is incorrect but I can't find anywhere that defines how this can be achieved.