I have an empty object and want to create an object inside object dynamically.
const obj = {}
obj["test1"]["test1.1"] = x //initialize to some variable
I get the error
Uncaught TypeError: Cannot set property 'test1.1' of undefined
I want the output to be like
obj = {
test1: {
test1.1: x //some variable
}
}
obj['test1'] = { 'test1.1': x }const obj = { test1: { "test1.1": x } }? Then you make the declaration, assignment, and full object creation all at once.