Select to view content in your preferred language

Adding a comma between multiple values

135
5
Jump to solution
yesterday
IanLadd_Tourmaline
Regular Contributor

Hello,

I have an Arcade script that inserts the name of a boundary polygon if it intersects with the feature. How do I show a comma between only the ones where it intersects multiple polygons? My current code just adds a "," to everyone regardless if it's only one value.

 

var land = FeatureSetByName($datastore,"Boundary_Aug2024",["Name"], true)
var intersectLayer = Intersects(land, Geometry($feature))
var result = '';
if (Count(intersectLayer) > 0) {
    for (var layer in intersectLayer) {
        result += layer.Name+(", ") ;
    }
} else {
    result = "Null"
}  
return result

 

 

Tags (1)
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You can add the items to an array and use the Concatenate function. This wouldn't add an extra comma if there is only one result.

var land = FeatureSetByName($datastore, "Boundary_Aug2024", ["Name"], true);
var intersectLayer = Intersects(land, Geometry($feature));
var result = [];
if (Count(intersectLayer) == 0) return "Null";
for (var layer in intersectLayer) {
  Push(result, layer.Name);
}
return Concatenate(result, ", ");

 

 

View solution in original post

5 Replies
clt_cabq
Frequent Contributor

Looks like you can nest if/else statements if you scroll down in the linked documentation to the section titled "Nested if/else". Another option it shows there is the IIF statement that might work for you as well

if else and other control logic  

IanLadd_Tourmaline
Regular Contributor

So I would create an nested if statement where if it's greater than one, then it inserts a comma between the values? How do I specify between them and not end up with another , after the end?

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You can add the items to an array and use the Concatenate function. This wouldn't add an extra comma if there is only one result.

var land = FeatureSetByName($datastore, "Boundary_Aug2024", ["Name"], true);
var intersectLayer = Intersects(land, Geometry($feature));
var result = [];
if (Count(intersectLayer) == 0) return "Null";
for (var layer in intersectLayer) {
  Push(result, layer.Name);
}
return Concatenate(result, ", ");

 

 

clt_cabq
Frequent Contributor

of course this is the best answer! Thanks for showing this approach @KenBuja 

0 Kudos
IanLadd_Tourmaline
Regular Contributor

Amazing! Thank you so much @KenBuja 

0 Kudos