The object property names in JavaScript are at the end of the line, your second example seems to work because the parenthesis property accessory converts the expression [1, 2]to String(return "1,2"), for example:
var obj = {};
obj[[1, 2]] = 3;
console.log(obj["1,2"]);
Another example:
var foo = { toString: function () { return "bar"; } },
obj = {};
obj[foo] = 3;
console.log(obj["bar"]);
See also:
source
share