Skip to main content

How to remove duplicates from an array of line items

  • January 11, 2022
  • 2 replies
  • 1658 views
How to remove duplicates from an array of line items
Troy Tessalone
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

Show content
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.

Did this topic help you find an answer to your question?

2 replies

  • Beginner
  • 5 replies
  • 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
Forum|alt.badge.img+14
  • Author
  • Zapier Expert
  • 30847 replies
  • February 12, 2022

@ubuntudroid 

Fixed