const key = 'name';
const value = 'james';
const obj = {
[key]: value
};
其他提示
var x = {}
x[first] = value
objArr[key] = x
Javascript object literal syntax treats unquoted keys as if they were quoted strings instead of variable names. You have to use bracket syntax to set properties with names computed at runtime.
(Why are you wrapping your code in a jQuery call? And you really should be using var declarations.)