Question

How to remove trailing comma from the list of emails in Zapier?

  • 13 June 2024
  • 1 reply
  • 10 views

Userlevel 2
Badge +1

Hi,

 

I have a Zap that I’m working on that is supposed to loop through a comma delimited list of email addresses.

 

As it stands, everything else works fine but the list sometime has a comma at the end of the final email which means that the final loop has an empty value and, therefore, errors.

 

Is there anyway to remove the final character from a text string? And, even better, a way to only remove it if it is a comma?

 

So it would take;

 

email1@email.com,email2@email.com,email3@email.com,email4@email.com,

 

And return;

 

email1@email.com,email2@email.com,email3@email.com,email4@email.com

 

Thanks,

 

Jon


1 reply

Userlevel 7
Badge +14

Hi @Jon Hall 

Use this Zap action: Code - Run JavaScript

// Remove trailing comma if present
emailList = inputData.emailList.replace(/,+$/, '');

output = [{emailList}]

 

Feedback from ChatGPT

 

Reply