为什么在JavaScript中[5,6,8,7][1,2]= 8 ?
16lz
2021-01-22
I can't wrap my mind around this quirk.
我想不起来这个怪癖。
[1,2,3,4,5,6][1,2,3]; // 4
[1,2,3,4,5,6][1,2]; // 3
I know [1,2,3] + [1,2] = "1,2,31,2"
, but I can't find what type or operation is being performed.
我知道[1、2、3]+[1、2]= "1、2、31、2",但我找不到正在执行的类型或操作。
4 个解决方案
#1
372
[1,2,3,4,5,6][1,2,3];
^ ^
| |
array + — array subscript access operation,
where index is `1,2,3`,
which is an expression that evaluates to `3`.
The second [...]
cannot be an array, so it’s an array subscript operation. And the contents of a subscript operation are not a delimited list of operands, but a single expression.
第二个[…不能是数组,所以它是数组下标操作。下标操作的内容不是限定操作数的列表,而是一个表达式。
Read more about the comma operator here.
在这里阅读更多有关逗号运算符的信息。
更多相关文章
- js之DOM操作(访问父节点parentNode)
- javascript对iframe的互操作浅析
- Python 内置函数及excel操作
- 【项目实战】自监控-09-DataFrame索引操作(上篇)
- Python文件操作大全,随机删除文件夹内的任意文件
- 使用Python操作MongoDB
- Cloud Pub / Sub Demo:403未授权用户执行此操作。当试图推送通知
- Python 文件的基本操作
- python 字符串操作