1

How can I accomplish this task:

var i = 'foo';
var x = {
          i: 'bar'
        }
console.log(x);
> {'foo':'bar'};

thanks!

1 Answer 1

5

Use bracket notation:

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

1 Comment

thanks, I had to have some kind of eclipse of my mind and I could not come up with this by my own!

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.