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.