Can anyone help me out with how to use Formatter to take a line-item list, turn it to text AND use appropriate list punctuation for a sentence. Example
apple
pear
plumb
cherry
becomes “apple, pear, plumb and cherry” instead of “apple, pear, plumb, cherry” ?
Best answer by ikbelkirasan
Hi @thurfirhawat - Instead of the formatter, you could use a code step with the following code in it:
const fruits = inputData.fruits.split(",").map((fruit) => fruit.trim()); let text = ""; fruits.forEach((fruit, index) => { if (index < fruits.length - 1) { if (index < fruits.length - 2) { text += `${fruit}, `; } else { text += `${fruit} and `; } } else { text += fruit; } });
output = [ { text } ]
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.