Zapier返回带有空字段的对象数组 - 需要添加空字符串

时间:2016-07-26 17:21:12

标签: javascript arrays zapier

我可以使用一些帮助在Zapier返回的数组中添加空字符串,以便用逗号表示空白的电子邮件。它看起来像这样:

输入电子邮件jbrooks_ca@yahoo.com,,,,jkburtie@gmail.com,skyelea@hotmail.com,等...

我喜欢它的样子是: jbrooks_ca@yahoo.com,'','','',jkburtie@gmail.com,skyelea@hotmail.com,

如果有人熟悉为Zapier编写JS,我会喜欢一些见解,因为我在编写JS方面不是很强。

以下是Zapier处理代码输出作为参考的两个屏幕。

the initial content pulled by Zapier

the output content once the JS has rendered

1 个答案:

答案 0 :(得分:2)

在Zapier Code框中试试这个:

var emails = input.email.split(',');
var new_emails_str = "";
for (var i in emails) {
    var e = emails[i];
    if (e) {
        new_emails_str += e + ",";
    } else {
        new_emails_str += "'',"; 
    }
}
output = [{emails: new_emails_str}];

截图:

enter image description here

我在测试时看到的结果:

enter image description here