Skip to main content

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

  1. apple
  2. pear
  3. plumb
  4. cherry

becomes “apple, pear, plumb and cherry” instead of “apple, pear, plumb, cherry”  ?

Hi @thurfirhawat 

Question - will the list *always* have 4 items in it?


No.  The items are variable.  There might be 0 to ?. @AndrewJDavison_Luhhu 


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
}
]