var a = {};
var b = {key: 'b'};
var c = {key: 'c'};
var d = [3,5,6];//等同于var e = ['3','5','6'] 也等同于 var f = ['3,5,6'] 等同于 var g = "3,5,6" 不等同于 var h = ['3,"5",6']
a[b] = 123;
a[c] = 345;
a[d] = 333;//等同于 a[3,5,6] 不等同于 a[3,"5",6]
console.log(a[b]);  // 345
console.log(a[c]);  // 345
console.log(a[d]);  // 333

总结:
对象作为key,无论对象是否嵌套,总会替换之前key的value
数组作为key,会先把数组中的元素转成字符串,之后如果相等,替换之前key的value,不相等,为新key


yzbao
626 声望19 粉丝

Uncaught ReferenceError