Search code examples
javascripthtmlnunjucks

Iterate through Map in HTML


I am trying to iterate through a Map object in HTML using for loop.

{%for s in objects%}
   <a>{{s}}</a>
{%endfor%}

The object is a Map (i.e. {a: b, c: d, e: f}) When I run this code, {{s}} will give me the value of the the object (i.e. b, d, f). How do I get the Key of this object?


Solution

  • Is this written in a templating engine? I think it looks like Nunjucks code.T

    This is from the Nunjucks homepage

    <ul>
      {% for name, item in items %}
      <li>{{ name }}: {{ item }}</li>
      {% endfor %}
    </ul>