Mustache.js: Get the index in an array

Let's fix Mustache.js looping through arrays but not finding the index.

Let's say we have the array animals = ["dogs", "cats", "wild boars"].

We can map this into an array of value-index objects., i) => { return {e: e, i: i} })

Integrate that with mustache.js and you get

return Mustache.render(`
      <li>{{i}} {{e}}</li>
  { animals_indexed: _ =>,i)=>{ return {e:e,i:i} })
javascript mustache

Edit on github
comments powered by Disqus
Click me