There is a Distinct function available in Arcade you can use to do this, however, you need to have an Array to return the unique values from. If you populate your result values into an array, you can use the Distinct function to return the unique results.
If you are happy with returning an array, then you can use the script below:
var fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);
var fsArray = Array(1);
var fsCount = Count(fs);
// check for features
if (fsCount > 0) {
for (var f in fs) {
// for each feature, add to the array
Push(fsArray, f.name)
}
} else {
return "No records available";
}
// return distinct values
return Distinct(fsArray);
If you prefer to return a text string instead, I modified the script slightly so that you can do that too. Just noting however that the first line returned is a "null" value creating an empty first line, which is why I've also added an Erase function to remove the 0 index.
var fs = FeatureSetByName($map, "returnDistinct" , ['*'], false);
var fsArray = Array(1);
var fsCount = Count(fs);
// check for features
if (fsCount > 0) {
for (var f in fs) {
// for each feature, add to the array
Push(fsArray, f.name)
}
} else {
return "No records available";
}
// return distinct values
// return Distinct(fsArray);
// return distinct values text
Erase(fsArray, 0); // remove 0-index "null" field
return Concatenate(Distinct(fsArray), TextFormatting.NewLine);
I hope that helps!