Im trying to create an dynamic object with dynamic keys eg:
var test = \"test\";
var obj = {
test:\"bananas\"
}
But I get an error:
obj[test + "ing"] = "bananas";
In relation to your edit:
var test = "test";
var obj = {};
obj[test] = "bananas";
or shorter:
var obj={[test]:"bananas"};
I normally wrap this in something like:
Object.expander = function(name, value, obj)
{
obj = obj || {};
obj[name] = value;
return obj;
};
var obj = Object.expander(test, "bananas");
you can't this way
try this instead
obj["testing"] = "bananas"