A relative beginner here in Arcade, as well as to posting questions on forums, but I can't find a solution for this particular issue...
I'm working in ArcPro, attempting to build a table using the Insert Table Attribute/Dynamic Text Element with a custom Arcade expression (Arcade being the only choice available). My first task is to remove or reduce duplicate Project_IDs that are paired with associated Site_IDs. Being familiar with Javascript, I tried several methods such as reduce() and forEach(), but kept ending up with the same error:
'Invalid expression. Error on line 6. Close parenthesis expected'
There are no syntax errors detected using VS Code, etc. And yet I'm at a loss...
Here's the code as it is now:
var pID = [$feature.PROJECT_ID];
function removeDuplicates(pID) {
var unique = [];
for(i=0; i < pID.length; i++){
if(unique.indexOf((pID[i]) === -1)){
unique.push(pID[i])
}
}
return unique;
}
return removeDuplicates(pID);
There are some syntax differences in Javascript and Arcade code. Here's a revised version showing those differences ("==" instead of "===", "Count" instead of "length", and the IndexOf and Push syntax).
var pID = [$feature.PROJECT_ID];
function removeDuplicates(pID) {
var unique = [];
for(var i=0; i < Count(pID); i++){
if(IndexOf(unique, (pID[i])) == -1){
Push(unique, pID[i])
}
}
return unique;
}
Ah, I figured there were some key differences between the two. The changes you made do 'solve' the error, however it returns only a delimiter for each record, while removing none of the duplicates.
What does your data look like? That would make it easier to figure out how to return the unique values.
I have a list of Project_IDs that have one or more Site_IDs, and I'm trying to list the sites under their respective projects (projectA -> Site1, Site2) instead of listing them individually (projectA -> Site1, ProjectA -> Site2)
I'll apply the changes you detailed earlier to the other methods I tried and see if it comes up with anything different.