Felicia Amy
Felicia Amy

Reputation: 51

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?

Upvotes: 1

Views: 3735

Answers (1)

Sean Kelly
Sean Kelly

Reputation: 991

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>

Upvotes: 3

Related Questions