0

First I want to create some dynamic properties in JavaScript object. Consider I have this code:

a ="field"
o = {}
o[a]="some field"
console.log(o)

o object will have field property with value "some field", but when I need to add property that has object as value I do this:

a ="field.foo"
o = {}
o[a]="child of field"
console.log(o)

than you can see that o have field.foo but when I access o.field.foo it returning undefined. What I want in the end is something like this:

{
   field :{foo:'child of field'}
}

but what I get is:

{
   field.foo:'child of field'
}

how to do that?

Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0