什么是JavaScript中的[1,2,3,4] [1,2] [英] What is [1,2,3,4][1,2] in javascript
本文介绍了什么是JavaScript中的[1,2,3,4] [1,2]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以通过解释来解释上述问题.我尝试过它的控制台,答案是3
can anyone explains the above question with explanation. I tried it console and the answer coming is 3
[1,2,3,4][1,2] //consoles 3
推荐答案
[1,2,3,4]
是 1,2
是两个数字,其中逗号之间的运算符,因此解析为 2
.
1,2
is two numbers with a comma operator between them, so resolves to 2
.
因此,您将从数组中获得索引2(第三项).
So you are getting index 2 (the third item) from the array.
var array = [1,2,3,4];
var property = (1,2);
var result = array[property];
console.log({ array: array, property: property, result: result });
这篇关于什么是JavaScript中的[1,2,3,4] [1,2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文