I have an empty root object created in JavsScript:
var myObject = {};
Now, I want to add a child object with a value:
{
"myObject ":{
"myChildObject":"FooBar"
}
}
Seems simple enough, but I'm having a hard time finding an answer. Most of the examples I find are related to DOM objects (div's) and don't really translate well. I've been looking at W3Schools on their .appendChild() page, but the examples there don't set a value.
myObject.myChildObject = 'foo'
or, if your key has spaces in it you can use square bracket notation:
myObject['my Child Object'] = 'foo'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With