Return

All Arcade expressions must return a value. The permissible data types returned from an Arcade expression are defined by the profile. There are two types of return statements: explicit returns and implicit returns.

Explicit returns

An explicit return is always preceded with the return keyword. This can be used for single-line expressions...

Use dark colors for code blocksCopy
1
return "Hello world";
Use dark colors for code blocksCopy
1
return ( ($feature.POP_2010 - $feature.POP_2000) / $feature.POP_2000) * 100;

...and multi-line expressions.

Use dark colors for code blocksCopy
1
2
var total = 5 + 10;
return total;
Use dark colors for code blocksCopy
1
2
3
4
5
6
var myArray = [10,20,30,40,50,60,70];
var total = 0;
for(var k in myArray){
  total += myArray[k];
}
return total;

It can also be used when defining functions.

Use dark colors for code blocksCopy
1
2
3
4
function calculateRatio(values, index){
  var value = values[index];
  return value / Sum(values);
}

Implicit returns

An implicit return returns the last executable statement of an expression. This is true regardless of an expression's length.

Use dark colors for code blocksCopy
1
2
5 + 10;
// returns 15
Use dark colors for code blocksCopy
1
($feature.POP_2010 / $feature.POP_2000) * 100;

Although the return keyword is not used in these multi-line expressions, the value of total is still returned.

Use dark colors for code blocksCopy
1
2
3
var total = 5 + 10;
total;
// returns 15
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
var myArray = [10,20,30,40,50,60,70];
var total = 0;
for(var k in myArray){
  total += myArray[k];
}
total;
// returns 280

User-defined functions can also be written with an implicit return.

Use dark colors for code blocksCopy
1
2
3
4
5
function calculateRatio(values, index){
  var value = values[index];
  // the value computed in the final statement is returned by the function
  value / Sum(values);
}

Guidelines

Expressions with explicit returns benefit from providing clarity to anyone reading it. When multi-line expressions lack an explicit return, it can be easily interpreted as incomplete or unfinished. The following are suggested guidelines when authoring expressions.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.