CODE MODE: Filter to Include/Exclude Items in Array

  • 24 November 2021
  • 5 replies
  • 31 views

Userlevel 7
Badge +12

CODE MODE: Filter to Include/Exclude Items in Array

 

Tips and Inspiration contributed by: Troy Tessalone | Automation Ace | Zapier Expert | #1 Zapier Community Contributor and Moderator

 

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

 

Filter By to EXCLUDE values in array

 

RESULTS

Code step results to INCLUDE values in an array.

 

Code step results to EXCLUDE values in an array.

 


5 replies

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?

Userlevel 7
Badge +12

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?

Userlevel 7
Badge +12

@erictobias 

Try adding this line after the filter line:

 

amazing. thank you!

Reply