How to filter an array or line items using a Code Step

  • 26 August 2020
  • 6 replies
How to filter an array or line items using a Code Step
Userlevel 5

Hi there, this is Erin Oz from the Zapier Support Team with another workflow idea to share!

Often a user wants to perform actions in their Zap only on certain items in an array.

The Filter by Zapier step does not filter each item in an array, so the solution here is to use a Code Step. You can use the filter method in Javascript to only allow the items you’d like to pass into the next steps of your Zap. 


This user has a Zap that triggers on a call ending. They would like to send a survey to all call participants that do not work at their company. What we’ll do here is use the filter method to only allow email addresses to continue in the Zap if they do not contain the domain. 

For example, let’s pretend we have a trigger step that returns an array of five email addresses - three of them end with, so we’d like to filter those out of the actions that come next. 

Our Code Step will accomplish three things: 

  1. All data that is brought into a Code Step is brought into the code as strings. In other words, even if the data being pulled in is already in an array, we will need to add code that turns the data into an array for the scope of the Code Step. 

const emailsArray = inputData.emails.split(",");

  1. The next line will filter out any email addresses containing ‘’. 

const filteredEmails = emailsArray.filter(email => !email.includes(''));

  1. The final line will output the array of filtered emails 

output = [{filtered_emails: filteredEmails}] 


The Input Data field is named emails, which is important to making this code work as expected! 


(view larger)


If you’d like to change this code to only allow emails that do contain ‘’, you can remove the “!” from !email.includes(‘

You can also change the search string from ‘’ to anything you’d like to filter on. :sunglasses:

We can see from our results here that we’ve removed the three email addresses that contained from the array, and only the emails from are returned in the output! 


(view larger)


​Does this make sense? Please let me know if you have any questions or need additional clarity on any of these steps!


6 replies

Userlevel 5

As a followup, let’s say you were expecting a variable number of email addresses each time the Zap runs, and you wanted your action steps to be repeated for each item returned in the array. 

For example, you want to send an email both to and, but next time your Zap runs there might be three clients! 

Check out Option 2 from @TimS’ excellent post here: 


Userlevel 7
Badge +10

Great post @erinoz - thanks!

Hi there @erinoz ! How can I do this with multiple conditions and multiple arrays?

Userlevel 1

How would I apply a filter to only return the elements in an array where one of the elements is a boolean value of ‘True’ (so don’t return the elements which are ‘False’ ?

Userlevel 7
Badge +12

@twelvetens Can you show us an example input? Thanks!

Userlevel 1

Sure thing! Here’s the output from my utilities step:


What I want to have is a filtered array, so in the example above, I would get both lines, but if any lines had ‘selected’ as True AND had ‘selectable’ as False, then I would not this lines returned.

Important to note that I’d need all of the line items detail returned for lines which pass the above logic, if that makes sense? So that I can grab all elements (price, qty etc) to use in further zap steps….