Functions

Functions define a block of statements to execute when the function is invoked. Functions help you avoid code duplication and simplify expressions. You can take advantage of functions native to the Arcade language, or define your own functions.

User-defined functions

Use the function keyword to define your own function. Functions must be declared before they are used and identified with a name that adheres to the following rules:

  • begins with a latin letter, underscore, or $
  • contains only latin letters, latin numbers, underscore, or $
  • must not match any reserved words.

Function identifiers are not case-sensitive. They have local scope, meaning any variables defined in them will only exist during the function's execution.

Function definitions may require parameters the expression provides as inputs to the calculation.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
// num and dem are parameters in the function.
// num {number} - Input parameter indicating the numerator in the calculation.
// dem {number} - Input parameter indicating the denominator in the calculation.
function calculatePercentage(num, dem) {
  var places = 2;
  return Round((num / dem) * 100, places);
  // num, dem, places are locally scoped to this function
}

calculatePercentage(50,75);  // returns 66.67

Arcade functions

Arcade provides out-of-the-box functions for your convenience. For example, Max and Area save you from writing long expressions with complicated code.

Use dark colors for code blocksCopy
1
2
3
4
var values = [-193, 0, 42, 40, 90];

// Max is a function available by default in the Arcade language
return Max(values);  // returns 90;
Use dark colors for code blocksCopy
1
return AreaGeodetic($feature, 'square-feet');

The function reference documents all Arcade functions that may be used in your expression. Some Arcade functions are not available in certain profiles. Each profile defines the function bundles expressions may use. Functions in the core bundle are available in every Arcade profile.

Chaining functions

Functions can be chained within other functions. See Chain FeatureSet Operations for examples of how to do this.

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