Skip to main content
Question

How do you remove duplicate values in an array in Appian ?

A
Anonymous
November 30, 2025

Answer

Will use union() to remove the duplicate elements


Code:

a!localVariables(
local!users: {
"Naruto",
"Sasuke",
"Itachi",
"Naruto",
"Madhara",
"Itachi"
},
union(local!users, local!users)
)


Output:

Image 16















Why union works here: union() merges lists, and the merged list holds each distinct value only once. That applies to duplicates inside a single list as well as across lists, so the output has no repeats even though both arguments are the same list.


The function expects at least two lists, so the list is passed twice. The second copy adds no new values, which leaves the first list with its duplicates removed.


Identify the duplicate elements in array and print it : Also they might may be a follow up question to write a code in Appain to print duplicate elements only from the given array. Below this code to print duplicate elements from the array


Code:

a!localVariables(
local!users: {
"Naruto",
"Sasuke",
"Itachi",
"Naruto",
"Madhara",
"Itachi"
},
local!uniqueUsers: union(local!users, local!users),
reject(
fn!isnull,
a!forEach(
local!uniqueUsers,
if(
count(wherecontains(fv!item, local!users)) > 1,
fv!item,
""
)
)
)
)


Output:

{"Naruto", "Itachi"}


Explanation:

This expression finds the names that appear more than once in a list and returns each of them once. Simply returns duplicates


What each part does

  1. local!users is a list of six names. “Naruto” and “Itachi” each appear twice.
  2. local!uniqueUsers: union(local!users, local!users) removes the duplicates, giving { "Naruto", "Sasuke", "Itachi", "Madhara" }, so each name is checked once instead of once per occurrence.
  3. a!forEach(local!uniqueUsers, ...) loops over those four names, with fv!item holding the current one.
  4. wherecontains(fv!item, local!users) returns the positions where the current name appears in the original list, duplicates included. For “Naruto” that is { 1, 4 }.
  5. count(...) > 1 is true when the name appears at more than one position, so it is a duplicate.
  6. if(..., fv!item, "") returns the name for a duplicate and an empty string otherwise.
  7. reject(fn!isnull, ...) removes the empty strings, leaving only the duplicated names.


Step by step


fv!item

Positions in

local!users

Count

Returned

Naruto

{ 1, 4 }

2

“Naruto”

Sasuke

{ 2 }

1

" "

Itachi

{ 3, 6 }

2

“Itachi”

Madhara

{ 5 }

1

" "

After the loop, the list is { "Naruto", "", "Itachi", "" }. Reject(fn!isnull,..) removes the empty values form the array.


Result

{ "Naruto", "Itachi" }

Try it yourself

Change the inputs or the expression and run it to see what it returns.

ri!users=

Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

JuniorExpressions#coding