How to use FOR Loops with Array of Line Items

  • 17 February 2022
  • 0 replies
  • 1026 views
How to use FOR Loops with Array of Line Items
Userlevel 7
Badge +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 users.

About

Using a FOR loop in a Code step can extend the ability to handle an array with line items.

 

How to Configure

 

Copy the Code

NOTE: The first item in an array is always 0.

let Set = inputData.Set;
let Item = inputData.Item;
let Prep = "";

Set = Set.split(","); // creates an array by splitting at each comma

// for loop
// let i = 0 sets the initial value for i
// i < Set.length is the condition that will be checked each time the loop runs
// i++ increments i each loop by +1
for (let i = 0; i < Set.length; i++) {
  Prep += Set[i] + Item + "\n"; // \n creates a new line
}

output = [{Prep, Item, Set}];

 

The Results

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.


0 replies

Be the first to reply!

Reply