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...

1
return "Hello world";
1
return ( ($feature.POP_2010 - $feature.POP_2000) / $feature.POP_2000) * 100;

...and multi-line expressions.

1
2
var total = 5 + 10;
return total;
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.

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.

1
2
5 + 10;
// returns 15
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.

1
2
3
var total = 5 + 10;
total;
// returns 15
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.

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.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close