为什么警报([“a”,“b”,“c”,“d”,“e”] [[1,2],3,4])在javascript中输出e?

时间:2011-09-05 13:47:40

标签: javascript alert

有人可以告诉我原因:

alert(["a","b","c","d","e"][[1,2],3,4]) 

在JavaScript中输出e?

1 个答案:

答案 0 :(得分:5)

因为逗号是一个执行所有分离指令的运算符(in fact:两条指令,每条指令也可以使用逗号运算符)并返回最后一条指令的结果。即:

["a","b","c","d","e"][[1,2],3,4] => ["a","b","c","d","e"][4] === "e"