简体   繁体   中英

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?

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.

return is not a function, by the way. You don't need the parenthesis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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