Type System

Arcade has a full type system. It implicitly casts between types where appropriate, using a predefined set of rules.

Each type is described below.

Number

Numbers are a single data type that are used in computations and Math functions.

They can be integers.

var x = 10;
var y = 100;

Or floating point values.

var z = 1.2;
var n = Number("1.2");

String values resembling numbers may be cast using the Number() function.

// n = 1.2
var n = number("1.2");

Two number constants are also available for your convenience. Click the links below to see the documentation for each.

Boolean

Boolean values evaluate to either true or false.

var x = true;
var y = false;

String values resembling a boolean may be cast using the Boolean() function.

// z = true
var z = boolean('true');

Text

The text type, also known as string, is a series of characters wrapped in single or double quotes. Any number or boolean may be converted to a text value using the Text() function.

var x = "This is a Text variable";
var z = 'This is also a text variable';

// n = "100"
var n = Text(100);

Several text constants are also available for your convenience. These allow you to insert special characters in text without needing to use escape characters. Click the links below to see the documentation for each.

Date

Dates describe a moment in time at various resolutions.

// Date only (no timestamp)
var x = Date(2007,11,1);  // December 1, 2007

// Date with timestamp
var n = Date(2008,11,1,12,55); // December 1, 2008 at 12:55 a.m.

Array

An object representing a list of elements. A single array can contain elements of various types, but they cannot have missing elements.

var z = [1,2,3];
var k = [1,2,"hello"];

return k[1];  // returns 2

z[0] = 23;  // z = [23,2,3]
z[3] = 24;  // Allowed as next sequential item;
z[1000] = 23 // Not allowed as would leave blanks;

You may iterate through the elements of an array using a for loop using the following syntax:

for (var index in myArray){
  // executes for each element in the array
}

Note that the variable index represents the index of the array, not the value of the element. So the following evaluates to 280:

var myArray = [10,20,30,40,50,60,70];
var sum = 0;
for(var k in myArray){
  sum += myArray[k];
}
// sum = 280
return sum;

Whereas the following slightly different code evaluates to 21:

var myArray = [10,20,30,40,50,60,70];
var sum = 0;
for(var k in myArray){
  sum += k;
}
// sum = 21
return sum;

Dictionary

A collection of key/value pairs. The keys of the dictionary are case insensitive.

var d = Dictionary("field1", 1, "field2",2);
return d.field1 + d["field2"];   // Can access elements with either notation


// Can also declare dictionaries using object notation.
var c = {
  "field1": 1,
  "field2": 2
}

Feature

Features have attributes and optionally a geometry.

var d = Feature(myGeometry, "field1", 1, "field2",2);
return d.field1 + d["field2"];   // Can access elements with either notation

return Geometry(d);  // Can get the geometry of the feature using the geometry function.

The Feature constructor is overloaded.

// Creating a Feature using a Dictionary
var feature = Feature(geom,  { "field1": 1, "field2": "myField2value" });

// You can also specify named parameters
var feature = Feature({ geometry: geom, attributes:   { "field1": 1, "field2": "myField2value" }  });

Geometry

Arcade includes five geometry types: Point, Multipoint, Polyline, Polygon, Extent. Geometry is immutable, meaning it is not possible to change the geometry after it is created.

Features contain geometry, which may be returned from the Geometry() function.

// returns the feature's geometry
Geometry($feature)

// Geometry Types have overloaded functions.
var pt = Point({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} });
var polyline = Polyline({ 'paths' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ],  [ [-97.06326,32.759], [-97.06298,32.755] ] ] , 'spatialReference':{'wkid':102100}});
var poly = Polygon(Polygon({'rings' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ],  [ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ] ], 'spatialReference':{'wkid':102100}}));
var env = Extent({  'xmin' : -109.55, 'ymin' : 25.76, 'xmax' : -86.39, 'ymax' : 49.94, 'spatialReference':{'wkid':102100} });
var mp = Multipoint({ 'points' : [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], 'spatialReference':{'wkid':102100} });

// General geometry creation. Will work out type from arguments.
var geom = Geometry({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} })

The following tables describe the specification of each geometry type.

Point

A point is a zero-dimensional geometry. This may be created by passing JSON in the format described below to the Point() function or by passing a point feature to the Geometry() function.

Property Type Description
x number The x-coordinate of the point.
y number The y-coordinate of the point.
z number The z-coordinate of the point. This may be null.
m number The m value of the point.
hasZ boolean Indicates if the geometry has a z-coordinate or elevation.
hasM boolean Indicates if the geometry has an m-value.
spatialReference Object The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry.

Multipoint

A multipoint is a zero-dimensional geometry. This may be created by passing JSON in the format described below to the Multipoint() function or by passing a multipoint feature to the Geometry() function.

Property Type Description
points Point[] An array of points making up the multipoint geometry.
hasZ boolean Indicates if the geometry has z-coordinates or elevation values.
hasM boolean Indicates if the geometry has m-values.
spatialReference Object The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry.

Polyline

A polyline is a one-dimensional geometry. This may be created by passing JSON in the format described below to the Polyline() function or by passing a polyline feature to the Geometry() function.

Property Type Description
paths number[][][] A three-dimensional array of numbers. The inner-most array contains the x,y,z,m coordinates of a single point. The second dimension contains additional points making up a line segment. The third dimension allows the polyline to have multiple segments.
hasZ boolean Indicates if the geometry has z-coordinates or elevation values.
hasM boolean Indicates if the geometry has m-values.
spatialReference Object The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry.

Polygon

A polygon is a two-dimensional geometry. This may be created by passing JSON in the format described below to the Polygon() function or by passing a polygon feature to the Geometry() function.

Property Type Description
rings number[][][] A three-dimensional array of numbers. The inner-most array contains the x,y,z,m coordinates of a single point. The second dimension contains additional points making up a ring, or line segment whose first point and last point match. The third dimension allows the polygon to have multiple rings.
hasZ boolean Indicates if the geometry has z-coordinates or elevation values.
hasM boolean Indicates if the geometry has m-values.
spatialReference Object The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry.

Extent

An extent is a bounding box describing an area of interest. This may be created by passing JSON in the format described below to the Geometry().

Property Type Description
xMax number The upper bound, or highest possible x-coordinate of the extent.
xMin number The lower bound, or lowest possible x-coordinate of the extent.
yMax number The upper bound, or highest possible y-coordinate of the extent.
yMin number The lower bound, or lowest possible y-coordinate of the extent.
zMax number The upper bound, or highest possible z-coordinate of the extent. This value may be null.
zMin number The lower bound, or lowest possible z-coordinate of the extent. This value may be null.
mMax number The upper bound, or highest possible m-value of the extent. This value may be null.
mMin number The lower bound, or lowest possible m-value of the extent. This value may be null.
hasZ boolean Indicates if the geometry has z-coordinates or elevation values.
hasM boolean Indicates if the geometry has m-values.
spatialReference Object The spatial reference of the geometry. This object contains a wkid property that indicates the Well-known ID of the geographic or projected coordinate system that defines the reference for which to draw the geometry.

Feedback on this topic?