简体   繁体   English

function 调用后的方括号是什么意思?

[英]What do square brackets after function call mean?

I'm trying to understand the purpose of the [0] in the function call I came across and what value is returned to x?我试图了解我遇到的 function 调用中 [0] 的用途以及返回给 x 的值是多少?

x = my_function(var1, var2)[0];

function my_function(v1, v2){
  var v3, v4

  v3 = v1 * 3;
  v4 = v2 * 7;

  return( [v3, v4] );
}

They mean that the function returns an array and you only need the first element of that array.他们的意思是 function 返回一个数组,您只需要该数组的第一个元素。

return is not a function, by the way.顺便说一句,return 不是 function。 You don't need the parenthesis.你不需要括号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM