I am using the Mustache templating library and trying to generate a comma separated list without a trailing comma, e.g.
red, green, blue
As the question is:
is there an elegant way of expressing a comma separated list without the trailing comma?
Then changing the data - when being the last item is already implicit by it being the final item in the array - isn't elegant.
Any mustache templating language that has array indices can do this properly,. ie. without adding anything to the data. This includes handlebars, ractive.js, and other popular mustache implementations.
{{# names:index}}
{{ . }}{{ #if index < names.length - 1 }}, {{ /if }}
{{ / }}