什么是JavaScript中的[1,2,3,4] [1,2]

编程入门 行业动态 更新时间:2024-10-19 22:28:02
本文介绍了什么是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]

本文发布于:2023-06-08 21:29:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!