Skip to main content

📌  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 filter to include/exclude items in an array?
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”.

 

Filter By to INCLUDE values in array

 

COPY THE CODE

let Set = inputData.Set.split(","); // creates array by splitting Input Data Variable at commas

let FilterBy = inputData.FilterBy; // value to filter the array by

Set = Set.filter(i => i.includes(FilterBy)); // INCLUDE values in array

output = <{Set}];

 

Filter By to EXCLUDE values in array

 

COPY THE CODE

let Set = inputData.Set.split(","); // creates array by splitting Input Data Variable at commas

let FilterBy = inputData.FilterBy; // value to filter the array by

Set = Set.filter(i => !i.includes(FilterBy)); // use ! EXCLUDE values in array

output = /{Set}];

 

RESULTS

Code step results to INCLUDE values in an array.

 

Code step results to EXCLUDE values in an array.

 

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.

This is super helpful but I have an array of number (0.00, 5.00, 10.00, and 20.00) and I am trying to exclude the 0.00.  When I set the FilterBy to 0.00, it excludes 0.00 but also excludes 10.00 and 20.00.  Any ideas?


Hi @erictobias 

Try changing the filter line to this:

 


Amazing!  Thank you so much!  It now returns 20.00, 10.00, and 5.00 as intended.  If I add Set.sort(); it returns 10.00 before 5.00.  Any idea how to solve that?


@erictobias 

Try adding this line after the filter line:

 


amazing. thank you!


I’m having trouble using this code to filter an array of Zoom Meetings by the Zoom meeting topic. I’m using a Input Data variable Set for the Zoom Array below and the FilterBy variable for the Zoom meeting topic. Any suggestions?

Here’s the array:

{"meetings":i{"uuid":"QmfjdPRnT1iPAx0Jgx+BBQ==","id":89233889087,"host_id":":censored:22:a70a31b480:","topic":"WPTI's Business Engagement Learning Lab (BELL)","type":8,"start_time":"2024-06-12T17:00:00Z","duration":150,"timezone":"America/New_York","agenda":"This is the Zoom link for all BELL sessions.","created_at":"2024-02-28T22:16:10Z","join_url":"https://wpti-org.zoom.us/j/89233889087"},{"uuid":"ZiW3r9TcSVuPkuRtgCkWmg==","id":89178616159,"host_id":":censored:22:a70a31b480:","topic":"2025 DYCD Zoom Registration Template","type":2,"start_time":"2024-09-18T03:00:00Z","duration":60,"timezone":"America/New_York","created_at":"2024-09-18T02:04:11Z","join_url":"https://wpti-org.zoom.us/j/89178616159"},{"uuid":"RD7dmjrSQrq+o7Es4Czxsg==","id":84538904667,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T12:00:00Z","duration":120,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-13T20:00:36Z","join_url":"https://wpti-org.zoom.us/j/84538904667?pwd=3BpBtsvOrNVINpwnisocoyy2RUVRAI.1"},{"uuid":"Gw+82S0BTxKSVIJvVMggUg==","id":84350956274,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T12:00:00Z","duration":120,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T02:33:32Z","join_url":"https://wpti-org.zoom.us/j/84350956274?pwd=Cm2X8egwrZ0UK2RbSqybMXolWQwXAD.1"},{"uuid":"Siwl1NsETVqsA2D0KLjvtQ==","id":84508039163,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T20:00:00Z","duration":0,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T06:20:33Z","join_url":"https://wpti-org.zoom.us/j/84508039163"},{"uuid":"N86fG3fLR+yk86sPBWLYcw==","id":88631515049,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T20:00:00Z","duration":0,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T06:33:39Z","join_url":"https://wpti-org.zoom.us/j/88631515049"},{"uuid":"jopE9qEATOCZKeF/ASZyvw==","id":83232327136,"host_id":":censored:22:a70a31b480:","topic":"120.0","type":2,"start_time":"2024-09-23T20:00:00Z","duration":0,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T06:15:45Z","join_url":"https://wpti-org.zoom.us/j/83232327136"},{"uuid":"ZDf9x2mRTD6kR3oO8hOiWA==","id":82059006875,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T20:00:00Z","duration":0,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T06:17:27Z","join_url":"https://wpti-org.zoom.us/j/82059006875"},{"uuid":"7wHANsWETsOf7MfbTRpzmw==","id":88150803243,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T20:00:00Z","duration":0,"timezone":"America/New_York","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T06:52:26Z","join_url":"https://wpti-org.zoom.us/j/88150803243"},{"uuid":"adqCE9ZRStKoWIBxTPDK6Q==","id":87894406540,"host_id":":censored:22:a70a31b480:","topic":"2022-08-09, Westchester Executive Roundtable","type":2,"start_time":"2024-09-23T23:00:00Z","duration":0,"timezone":"America/Los_Angeles","agenda":"Description and more description. Here's some bold","created_at":"2024-09-18T03:56:14Z","join_url":"https://wpti-org.zoom.us/j/87894406540?pwd=vu3V6bsFofLQ5eweWT3DrvqytD7YDR.1"},{"uuid":"Y7A+FK4pTJGAWbO5yLShEg==","id":83497617384,"host_id":":censored:22:a70a31b480:","topic":"Artificial Intelligence in Workforce Development: AI and Its Impact ","type":2,"start_time":"2024-10-17T17:00:00Z","duration":120,"timezone":"America/New_York","agenda":"Target Audience: Front-Line Staff, Supervisors, Program Directors \n\nFacilitators: Justin Collins\nCo-Facilitator: Yanni Deconescu \n\nArtificial Intelligence (AI) \u2013 including Generative AI like ChatGPT \u2013 is rapidly changing the way we work, and by exten","created_at":"2024-09-19T13:18:17Z","join_url":"https://wpti-org.zoom.us/j/83497617384"},{"uuid":"rWsVoHZVSfK7Lktn+WKdcA==","id":88938959676,"host_id":":censored:22:a70a31b480:","topic":"AI Tools for Workforce Development","type":2,"start_time":"2025-01-23T18:00:00Z","duration":120,"timezone":"America/New_York","agenda":"Target audience: Front-Line Staff, Supervisors, Program Directors\n\nFacilitators: Justin Collins\nCo-Facilitator: Yanni Deconescu \n\nTraining Description: Artificial Intelligence (AI) is not only changing the way the world works, it also offers helpful ","created_at":"2024-09-19T13:26:04Z","join_url":"https://wpti-org.zoom.us/j/88938959676"}]}


Hi @mountainrog 

Probably best to start your own topic, and include how your Zap steps are outlined and configured in EDIT mode along with any encountered errors.


Reply