janl / mustache.js

Minimal templating with {{mustaches}} in JavaScript
https://mustache.github.io
MIT License
16.44k stars 2.4k forks source link

show arrays in comma separated way using last #821

Open afattahi54 opened 1 year ago

afattahi54 commented 1 year ago

I want to print a list as a comma separated values of an array.

I found below code works in some implementation (ex: mustache

const myArray = ["apple", "banana", "orange"];
const template = "{{#myArray}}{{.}}{{^last}}, {{/last}}{{/myArray}}";
const output = Mustache.render(template, { myArray });
console.log(output); // Output: "apple, banana, orange"

I have test and it seems that there is no last tag.

Is there alternative? what is the best way to have this result