What's wrong with this? How should I be doing it?
var arr = ['image', 'image.jpg'];
var obj = {arr[0]: arr[1]};
What's wrong with this? How should I be doing it?
var arr = ['image', 'image.jpg'];
var obj = {arr[0]: arr[1]};
The problem is that expressions like arr[0]
cannot be used as keys in the literal initializer notation of an object. Instead, the property must be assigned dynamically.
var arr = ['image', 'image.jpg'];
var obj = {};
obj[arr[0]] = arr[1];