括号如何在数组中工作?(javascript) [英] How does parentheses work in arrays? (javascript)

查看:39
本文介绍了括号如何在数组中工作?(javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 this.array [0] = [(2,1)] <,我不明白为什么 this.array [0] 等于 1 /code>?Javascript与2有什么作用,我如何使用/使用它?括号如何在数组内部工作?

I don't get why this.array[0] equals 1 if this.array[0] = [(2,1)]? What does Javascript do with the 2 and how do i reach/use it? How does parenthesis work inside arrays?

如果布尔值是true还是false,我想用 X 做不同的事情. this.array [0] = [(true,X)] this.array [0] = [(false,X)] .

I'd like to do different things with X if the boolean before it is true or false. this.array[0] = [(true, X)] and this.array[0] = [(false, X)].

推荐答案

在该上下文中,括号用作语句,最后传递的项目是传递的值.

Parenthesis in that context act as a statement with the last item passed being the passed value.

换句话说:

(2, 1) === 1

但是,对 2 进行了评估,所以:

The 2 is evaluated, however, so:

(foo(), bar())

有效地做到了:

foo();
return bar();

在这种情况下,您想要的是[2,1]

What you want in this case is [2, 1]

这篇关于括号如何在数组中工作?(javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆