I am using Mustache and using the data
{ \"names\": [ {\"name\":\"John\"}, {\"name\":\"Mary\"} ] }
My mustache template is:
I'm using a pre calculate function to inject '@index' into array.
const putIndexInArray = array => {
let putIndex = (value, index) => {
value['@index'] = index;
return value;
};
if (!Array.isArray(array)) {
return array;
}
return array.map(putIndex);
};
Mustache.render(template, {
array: putIndexInArray(['Homer', 'Marge', 'Lisa'])
});
and then using like this:
{{#array}}
{{@index}}
{{/array}}