为什么这个 javascript 代码有效并且在括号内使用逗号?

Why is this javascript code valid and works with comma inside brackets?

var a = {
  key1: 1,
  key2: 2
};
console.log(a['key1', 'key2']); // print 2

第2行打印值2,我不明白为什么我没有语法错误。

此代码运行良好,因为您使用的是 Comma operator,因此它将计算所有操作数和 return 最后计算的一个。

The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.