javascript using variables for object keys and values

javascript, jquery

Solution

You should do

var key1 = something;
var key2 = something;
var value1 = something;
var value2 = something;

var attributes = {};

attributes[key1] = value1;

Problem

I have the following code: ``` pub.call_response = function() { return { units: [ { test_attributes: { } } ] }; }; ``` I have a set of variables that I need to use for the keys/values in `test_attributes` as follows: ``` var key1 = something; var key2 = something; var value1 = something; var value2 = something; pub.call_response = function() { return { units: [ { test_attributes: { key1: value1, key2: value2 } } ] }; }; ``` Obviously, this does not work. Does anyone have any ideas on how to do something like this? Using jQuery is acceptable. Thanks!

Original source