I want to replace "placeholder" with {"John": "Dough"} dynamically with a function call.
This works:
a = {foo:{bar:{baz:"placeholder"}}};
a.foo.bar.baz = {"John" : "Dough"};
console.log(JSON.stringify(a));
> {"foo":{"bar":{"baz":{"John":"Dough"}}}}
But this doesn't:
var test = function(key, value) {
a = {foo:{bar:{baz:"placeholder"}}};
a.foo.bar.baz = { key: value};
console.log(JSON.stringify(a));
};
test("John", "Dough");
> {"foo":{"bar":{"baz":{"key":"Dough"}}}}
This also doesn't work:
var test = function(key, value) {
a = {foo:{bar:{baz:"placeholder"}}};
a.foo.bar.baz[key] = value;
console.log(JSON.stringify(a));
};
test("John", "Dough");
> {"foo":{"bar":{"baz":"placeholder"}}}
I am testing on Node.js. Probably won't change in browser.