Using a variable as part of a javascript object property
Another very simple question.
I have some code like this:
var a = {"foo":"bar"};
Which creates an object called a
with a property called foo
with value bar
.
I'd like to do this:
var propName = "foo";
a = {propName:"bar"};
And for th开发者_高级运维e two a
objects to be the same.
How do I do that?
(Context is that I'm building an object to pass to jQuery's css method)
You must set it in two steps:
var a = {};
a[propName] = 'bar';
精彩评论