PageSourceSearch

https://embedded-workflow-builder.netlify.app/looping/

html embedded-workflow-builder.netlify.app collected 2026-10-03 10:41:43 UTC 35,453 bytes, 43 lines download raw bytes

1<!doctype html><html lang=en dir=ltr class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-looping" data-has-hydrated=false><head><meta charset=UTF-8>
2<!-- This site is hosted on Netlify. Anyone can build and deploy a site
3     like this one for free: https://netlify.new/?utm_campaign=loops&utm_source=ai-legible&utm_medium=owned&utm_content=comment&utm_id=636a1b7a-1cdb-4986-9540-f22a191f7599
4     Netlify hosting facts for this site: static/SSR served via Netlify Edge. --><meta name=generator content="Docusaurus v3.10.2"><title data-rh=true>Looping | Acme Inc Workflow Builder</title><meta data-rh=true name=viewport content="width=device-width, initial-scale=1.0"/><meta data-rh=true name=twitter:card content=summary_large_image /><meta data-rh=true property=og:url content=https://docs.acme.com/looping /><meta data-rh=true property=og:locale content=en /><meta data-rh=true name=docusaurus_locale content=en /><meta data-rh=true name=docsearch:language content=en /><meta data-rh=true name=docusaurus_version content=current /><meta data-rh=true name=docusaurus_tag content=docs-default-current /><meta data-rh=true name=docsearch:version content=current /><meta data-rh=true name=docsearch:docusaurus_tag content=docs-default-current /><meta data-rh=true property=og:title content="Looping | Acme Inc Workflow Builder"/><meta data-rh=true name=description content="The loop step allows you to iterate over an array of items or records"/><meta data-rh=true property=og:description content="The loop step allows you to iterate over an array of items or records"/><link data-rh=true rel=icon href=/img/example-logo.svg /><link data-rh=true rel=canonical href=https://docs.acme.com/looping /><link data-rh=true rel=alternate href=https://docs.acme.com/looping hreflang=en /><link data-rh=true rel=alternate href=https://docs.acme.com/looping hreflang=x-default />
4<script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","item":"https://docs.acme.com/looping","name":"Looping","position":1}]}</script>
4<link rel=stylesheet href=/assets/css/styles.e19969b2.css />
4<script src=/assets/js/runtime~main.313494e9.js defer></script>
4<script src=/assets/js/main.a6a42398.js defer></script>
4</head><body><svg style="display: none;"><defs>
5<symbol id=theme-svg-external-link viewBox="0 0 24 24"><path fill=currentColor d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"/></symbol>
6</defs></svg>
7<script>!function(){var t=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme-70e")}catch(t){}}();document.documentElement.setAttribute("data-theme",t||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")),document.documentElement.setAttribute("data-theme-choice",t||"system")}(),function(){try{for(var[t,e]of new URLSearchParams(window.location.search).entries())if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script>
7<div id=__docusaurus><link rel=preload as=image href=/img/example-logo.svg /><div role=region aria-label="Skip to main content"><a class=skipToContent_fXgn href=#__docusaurus_skipToContent_fallback>Skip to main content</a></div><nav aria-label=Main class="theme-layout-navbar navbar navbar--fixed-top"><div class=navbar__inner><div class="theme-layout-navbar-left navbar__items"><a class=navbar__brand href=/><div class=navbar__logo><img src=/img/example-logo.svg alt="Acme logo" class="themedComponent_mlkZ themedComponent--light_NVdE"/><img src=/img/example-logo.svg alt="Acme logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"/></div><b class="navbar__title text--truncate">Acme Workflow Builder</b></a></div><div class="theme-layout-navbar-right navbar__items navbar__items--right"><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type=button disabled title="system mode" aria-label="Switch between dark and light mode (currently system mode)"><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP lightToggleIcon_pyhR"><path fill=currentColor d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP darkToggleIcon_wfgR"><path fill=currentColor d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP systemToggleIcon_QzmC"><path fill=currentColor d="m12 21c4.971 0 9-4.029 9-9s-4.029-9-9-9-9 4.029-9 9 4.029 9 9 9zm4.95-13.95c1.313 1.313 2.05 3.093 2.05 4.95s-0.738 3.637-2.05 4.95c-1.313 1.313-3.093 2.05-4.95 2.05v-14c1.857 0 3.637 0.737 4.95 2.05z"/></svg></button></div><div class=navbarSearchContainer_Bca1></div></div></div><div role=presentation class=navbar-sidebar__backdrop></div></nav><div id=__docusaurus_skipToContent_fallback class="theme-layout-main main-wrapper mainWrapper_z2l0"><div class=docsWrapper_hBAB><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type=button></button><div class=docRoot_UBD9><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class=sidebarViewport_aRkj><div class=sidebar_njMd><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class=menu__link href=/><span class=linkLabel_WmDU>Acme Inc's Workflow Builder</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class=menu__link href=/get-started><span class=linkLabel_WmDU>Getting Started</span></a><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" role=button aria-expanded=true href=/building><span class=categoryLinkLabel_W154>Workflow Builder</span></a></div><ul class=menu__list><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/building><span class=linkLabel_WmDU>Building Workflows</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/branching><span class=linkLabel_WmDU>Branching</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current=page tabindex=0 href=/looping><span class=linkLabel_WmDU>Looping</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/triggering><span class=linkLabel_WmDU>Triggering Workflows</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/testing><span class=linkLabel_WmDU>Testing Workflows</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/enabling><span class=linkLabel_WmDU>Enabling Workflows</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/oauth2><span class=linkLabel_WmDU>OAuth 2.0 Connections</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/error-handling><span class=linkLabel_WmDU>Error Handling</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/http-requests><span class=linkLabel_WmDU>HTTP Requests</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/custom-code><span class=linkLabel_WmDU>
7Custom Code</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/runner-environment><span class=linkLabel_WmDU>Runner Environment and Limits</span></a></ul><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" href=/category/connectors><span class=categoryLinkLabel_W154>Connectors</span></a><button aria-label="Expand sidebar category 'Connectors'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div></ul></nav></div></div></aside><main class=docMainContainer_TBSr><div class="container padding-top--md padding-bottom--lg"><div class=row><div class="col docItemCol_VOVn"><div class=docItemContainer_Djhp><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label=Breadcrumbs><ul class=breadcrumbs><li class=breadcrumbs__item><a aria-label="Home page" class=breadcrumbs__link href=/><svg viewBox="0 0 24 24" class=breadcrumbHomeIcon_YNFT><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill=currentColor /></svg></a><li class=breadcrumbs__item><span class=breadcrumbs__link>Workflow Builder</span><li class="breadcrumbs__item breadcrumbs__item--active"><span class=breadcrumbs__link>Looping</span></ul></nav><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type=button class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><header><h1>Looping</h1></header><p>For many Workflows, it's useful to be able to loop over an array of items or to loop a certain number of times.
8If your Workflow processes files on an SFTP server, for example, you might want to loop over an array of files on the server.
9If your Workflow sends alerts to users, you might want to loop over an array of users.</p>
10<p>The <a class="" href=/connectors/loop>loop</a> connector allows you to loop over each item in an array, or you can loop a predetermined number of times.
11After adding a <strong>loop</strong> step to your Workflow, you can then add steps within the loop that will execute repeatedly.</p>
12<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=looping-over-arrays-of-records>Looping over arrays of records<a href=#looping-over-arrays-of-records class=hash-link aria-label="Direct link to Looping over arrays of records" title="Direct link to Looping over arrays of records" translate=no>​</a></h2>
13<p>Imagine you have a step that returns an array of records:</p>
14<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockTitle_OeMC>Result of 'List Contacts' step</div><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-json codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token punctuation" style=color:#393A34>[</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"first"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"John"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"last"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Doe"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>
14"country"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"US"</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"first"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Lisa"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"last"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Nguyen"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"country"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"AUS"</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"first"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Sarah"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"last"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Smith"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token property" style=color:#36acaa>"country"</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"GB"</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>}</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>]</span><br/></div></code></pre></div></div>
15<p>
15A loop step can then be configured to loop for each record by referencing the <code>results</code> of the <strong>List Contacts</strong> step:</p>
16<p><img decoding=async loading=lazy alt="Loop step reference results" src=/assets/images/loop-step-reference-results-53e93bfaad5a1683cb945a9213ea2a35.png width=1155 height=655 class=img_ev3q /></p>
17<p>If you're familiar with JavaScript programming, this is similar to running</p>
18<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-js codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token keyword control-flow" style=color:#00009f>for</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>(</span><span class="token keyword" style=color:#00009f>const</span><span class="token plain"> record </span><span class="token keyword" style=color:#00009f>of</span><span class="token plain"> records</span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token function" style=color:#d73a49>doThing</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">record</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><br/></div></code></pre></div></div>
19<p>The loop step provides a few properties to steps within the loop:</p>
20<ul>
21<li class=""><code>currentItem</code> represents the item in the array that is currently being processed</li>
22<li class=""><code>index</code> represents the <a href=https://en.wikipedia.org/wiki/Zero-based_numbering target=_blank rel="noopener noreferrer" class="">zero-indexed</a> index of the current value.</li>
23<li class=""><code>isFirst</code> is <code>true</code> if the current item is the first item in the array, and <code>false</code> otherwise.</li>
24<li class=""><code>isLast</code> is <code>true</code> if the current item is the last item in the array, and <code>false</code> otherwise.</li>
25</ul>
26<p>Using the example above, during the second loop cycle <code>currentItem</code> would equal <code>{ "first": "Lisa", "last": "Nguyen", "country": "AUS" }</code> and <code>index</code> would equal <code>1</code>.</p>
27<p>If you would like to use values of the current item, you can reference things like <code>currentItem.country</code> in the example above as an input for a step.</p>
28<p><img decoding=async loading=lazy alt="Current item reference" src=/assets/images/current-item-reference-8e44ab0e5cf93bbc9e5bb89e705de402.png width=1064 height=965 class=img_ev3q /></p>
29<p>If you use a <a class="" href=/custom-code>code step</a> within a loop, you can reference <code>currentItem</code> and <code>index</code> like this:</p>
30<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockTitle_OeMC>Example code step referencing a loop's current item</div><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-js codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token plain">module</span><span class="token punctuation" style=color:#393A34>.</span><span class="token method-variable function-variable method function property-access" style=color:#d73a49>exports</span><span class="token plain"> </span><span class="token operator" style=color:#393A34>=</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>async</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token parameter punctuation" style=color:#393A34>
30{</span><span class="token parameter"> logger </span><span class="token parameter punctuation" style=color:#393A34>}</span><span class="token parameter punctuation" style=color:#393A34>,</span><span class="token parameter"></span><br/></div><div class=token-line style=color:#393A34><span class="token parameter">  </span><span class="token parameter punctuation" style=color:#393A34>{</span><span class="token parameter"> </span><span class="token parameter literal-property property" style=color:#36acaa>loopOverContacts</span><span class="token parameter operator" style=color:#393A34>:</span><span class="token parameter"> </span><span class="token parameter punctuation" style=color:#393A34>{</span><span class="token parameter"> currentItem</span><span class="token parameter punctuation" style=color:#393A34>,</span><span class="token parameter"> index </span><span class="token parameter punctuation" style=color:#393A34>}</span><span class="token parameter"> </span><span class="token parameter punctuation" style=color:#393A34>}</span><span class="token parameter punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token arrow operator" style=color:#393A34>=></span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  logger</span><span class="token punctuation" style=color:#393A34>.</span><span class="token method function property-access" style=color:#d73a49>info</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">    </span><span class="token template-string template-punctuation string" style=color:#e3116c>`</span><span class="token template-string string" style=color:#e3116c>User #</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">index </span><span class="token template-string interpolation operator" style=color:#393A34>+</span><span class="token template-string interpolation"> </span><span class="token template-string interpolation number" style=color:#36acaa>1</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string string" style=color:#e3116c>: </span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">currentItem</span><span class="token template-string interpolation punctuation" style=color:#393A34>.</span><span class="token template-string interpolation property-access">first</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string string" style=color:#e3116c> </span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">currentItem</span><span class="token template-string interpolation punctuation" style=color:#393A34>.</span><span class="token template-string interpolation property-access">last</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string string" style=color:#e3116c> from </span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">currentItem</span><span class="token template-string interpolation punctuation" style=color:#393A34>.</span><span class="token template-string interpolation property-access">country</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string template-punctuation string" style=color:#e3116c>
30`</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>;</span><br/></div></code></pre></div></div>
31<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=looping-a-certain-number-of-times>Looping a certain number of times<a href=#looping-a-certain-number-of-times class=hash-link aria-label="Direct link to Looping a certain number of times" title="Direct link to Looping a certain number of times" translate=no>​</a></h2>
32<p>Sometimes you'll want to loop a set number of times.
33For those situations, a <a class="" href=/connectors/loop#loopntimes>Repeat X Times</a> action can help.</p>
34<p>Programmatically, the <strong>Repeat X Times</strong> action is similar to a <code>for</code> loop like this:</p>
35<div class="language-js codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-js codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token keyword control-flow" style=color:#00009f>for</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>(</span><span class="token keyword" style=color:#00009f>let</span><span class="token plain"> index </span><span class="token operator" style=color:#393A34>=</span><span class="token plain"> </span><span class="token number" style=color:#36acaa>0</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"> index </span><span class="token operator" style=color:#393A34>&lt;</span><span class="token plain"> </span><span class="token constant" style=color:#36acaa>SOME_NUMBER</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"> index</span><span class="token operator" style=color:#393A34>++</span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">  </span><span class="token function" style=color:#d73a49>doThing</span><span class="token punctuation" style=color:#393A34>(</span><span class="token plain">index</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><br/></div></code></pre></div></div>
36<p>Like <a href=#looping-over-arrays-of-records class="">looping over arrays</a>, <strong>Repeat X Times</strong> provides a <code>currentItem</code> and <code>index</code>, which both represent the same thing (a <a href=https://en.wikipedia.org/wiki/Zero-based_numbering target=_blank rel="noopener noreferrer" class="">zero-indexed</a> count of the current loop iteration).
37So, the first loop iteration <code>index</code> will be <code>0</code>, the second iteration will have an <code>index</code> of <code>1</code>, etc.</p>
38<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=return-values-of-loops>Return values of loops<a href=#return-values-of-loops class=hash-link aria-label="Direct link to Return values of loops" title="Direct link to Return values of loops" translate=no>​</a></h2>
39<p>A loop will collect the results of the <strong>last</strong> step within the loop and will save those results as an array.</p>
40<p>For example, if the last step of a loop returns a string like this:</p>
41<div class="language-javascript codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-javascript codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token plain">module</span><span class="token punctuation" style=color:#393A34>.</span><span class="token method-variable function-variable method function property-access" style=color:#d73a49>exports</span><span class="token plain"> </span><span class="token operator" style=color:#393A34>=</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>async</span><span class="token punctuation" style=color:#393A34>(</span><span class="token parameter">context</span><span class="token parameter punctuation" style=color:#393A34>,</span><span class="token parameter"> </span><span class="token parameter literal-property property" style=color:#36acaa>loopOverContacts</span><span class="token parameter operator" style=color:#393A34>:</span><span class="token parameter"> </span><span class="token parameter punctuation" style=color:#393A34>
41{</span><span class="token parameter"> currentItem </span><span class="token parameter punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>)</span><span class="token plain"> </span><span class="token arrow operator" style=color:#393A34>=></span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain">    </span><span class="token keyword control-flow" style=color:#00009f>return</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token literal-property property" style=color:#36acaa>data</span><span class="token operator" style=color:#393A34>:</span><span class="token plain"> </span><span class="token template-string template-punctuation string" style=color:#e3116c>`</span><span class="token template-string string" style=color:#e3116c>Processed </span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">currentItem</span><span class="token template-string interpolation punctuation" style=color:#393A34>.</span><span class="token template-string interpolation property-access">first</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string string" style=color:#e3116c> from </span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>${</span><span class="token template-string interpolation">currentItem</span><span class="token template-string interpolation punctuation" style=color:#393A34>.</span><span class="token template-string interpolation property-access">country</span><span class="token template-string interpolation interpolation-punctuation punctuation" style=color:#393A34>}</span><span class="token template-string template-punctuation string" style=color:#e3116c>`</span><span class="token punctuation" style=color:#393A34>}</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><br/></div></code></pre></div></div>
42<p>Then the <code>result</code> of the loop will yield:</p>
43<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-json codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token punctuation" style=color:#393A34>[</span><span class="token string" style=color:#e3116c>"Processed John from US"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Processed Lisa from AUS"</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token string" style=color:#e3116c>"Processed Sarah from GB"</span><span class="token punctuation" style=color:#393A34>]</span><br/></div></code></pre></div></div></div></article><nav class="docusaurus-mt-lg pagination-nav" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href=/branching><div class=pagination-nav__sublabel>Previous</div><div class=pagination-nav__label>Branching</div></a><a class="pagination-nav__link pagination-nav__link--next" href=/triggering><div class=pagination-nav__sublabel>Next</div><div class=pagination-nav__label>Triggering Workflows</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href=#looping-over-arrays-of-records class="table-of-contents__link toc-highlight">Looping over arrays of records</a><li><a href=#looping-a-certain-number-of-times class="table-of-contents__link toc-highlight">
43Looping a certain number of times</a><li><a href=#return-values-of-loops class="table-of-contents__link toc-highlight">Return values of loops</a></ul></div></div></div></div></main></div></div></div><footer class="theme-layout-footer footer footer--dark"><div class="container container-fluid"><div class="footer__bottom text--center"><div class=footer__copyright>Copyright © 2026 Acme Inc</div></div></div></footer></div></body>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.