1

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 the 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)

1 Answer 1

4

You must set it in two steps:

var a = {};
a[propName] = 'bar';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.