Friday, February 21, 2014

add a property to a JavaScript object based on dynamic content

var foo = {};
var bar = "baz";
foo[bar] = "qux";

 
 

If one calls foo.baz after the lines of code above, "qux" will be returned. The "baz" magic string may not be "dynamic" really, but you get the idea, right?

No comments:

Post a Comment