Skip to content

Instantly share code, notes, and snippets.

@saltukalakus
Created September 10, 2015 11:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save saltukalakus/d89ee29c16e216cccbbe to your computer and use it in GitHub Desktop.
Replace a JSON property dynamically in a function call
var test = function(key, value) {
a = {foo:{bar:{baz:"placeholder"}}};
a.foo.bar.baz = {}; //creating a new object as `baz` value then assign
a.foo.bar.baz[key] = value;
console.log(JSON.stringify(a));
};
test("Jon", "Dough");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment