Skip to main content

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

Hi @Jon Hall 

Use this Zap action: Code - Run JavaScript

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

output = {emailList}]

 

Feedback from ChatGPT