Question: Loop througth string consists of array in ejs file in node js

Question

Loop througth string consists of array in ejs file in node js

Answers 0
Added at 2016-12-22 15:12
Tags
Question

I am working on node project. I am able to loop through array but my requirement is to loop through string consists of array. Example of my object key is :

"location" : "[{ \"dark\": \"10\", \"light\": \"50\", \"date\": \"10-10-2016\"},{ \"dark\": \"10\", \"light\": \"50\", \"date\": \"10-10-2016\"},{ \"dark\": \"10\", \"light\": \"50\", \"date\": \"10-10-2016\"}]"

I am using Nunjunks template engine for my ejs file setup. I search and get JSON.parse() can be used but how to use this with template looping like this example:

{% block content %}
<ul>
  {% for name, item in items %}
  <li>{{ name }}: {{ item }}</li>
  {% endfor %}
</ul>
{% endblock %}
Answers
Source Show
◀ Wstecz