Erik L
Erik L

Reputation: 195

How to to use each in pug with an array

So I have a json file have where I have an array called technologies, I am trying to get a list of the array to be rendered in a pug file like this:

How I want the array data to be rendered in pug

{


            "projects": [
                {
                    "id": "0",
                    "project_name": "A random quote generator",
                    "description": "This is a project that displays a random quote each time the button is clicked or every 5 seconds",
                    "technologies": ["HTML", "CSS", "JAVASCRIPT"],

}

This is how I am currently trying to use each in my pug file

 ul
           each val in `${projects[id].technologies}`
             li=  val

And this is how the data in currently being rendered, which I don't want

Current data output

Can someone help?

Upvotes: 2

Views: 520

Answers (1)

Chiller
Chiller

Reputation: 9738

Using template ${projects[id].technologies} converts the array ["HTML", "CSS", "JAVASCRIPT"] to a string, and when you loop throw a string you get letters and not array items

You should use something like this:

ul
   each val in projects[id].technologies
        li= val

Upvotes: 2

Related Questions