Skip to main content

How to remove duplicates from an array of line items

  • January 11, 2022
  • 2 replies
  • 1789 views
How to remove duplicates from an array of line items
Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14

📌  We do our best to ensure that the code in these articles works as advertised, but please be aware that Zapier Support does not officially help with code steps due to their advanced nature. Feel free to comment on the article or ask in the Zapier Community, where we have code-savvy folks (including the author of this post).

Q: Ever wanted to remove duplicates from an array of line items?
A: Use a Code app as a Zap step: https://zapier.com/apps/code/help

Code step configuration using JavaScript

NOTE: Map your line items array to the right side value for the “Set” Input Data variable in place of “A,B,C,C,B,A”.

Copy the Code

let Set = inputData.Set.split(","); // creates array by splitting Input Data variable at commas

let Distinct = []; // empty array to store the unique values

Set.forEach((i) => {
if (!Distinct.includes(i)) {
Distinct.push(i);
}
});

output = [{Set, Distinct}];

 

Results

Code step results WITH removing duplicate values from an array of line items

Contribution by Troy Tessalone

Troy is a Certified Zapier Expert who automates workflows with no-code and low-code apps to help clients save time and make money.

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

  • Beginner
  • February 12, 2022

Great script, super helpful! 🙏 Minor nitpick which prevents compilation: there is a missing `{` in the last line of your code. 


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Author
  • Zapier Orchestrator & Solution Partner
  • February 12, 2022

@ubuntudroid 

Fixed