Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
Nunjucks nested for loop sort

I am new to nunjucks.

I am trying to sort by a value in the nested for loop. As the sort can only happen in the parent for loop I am unsure how to achieve this. I can sort using a key in the parent for loop but I am not sure how to use a key from the nested for loop in the sort in the parent for loop. (Confusing I know)

   {% for stats in countries | sort(true, false, config.sortBy) %}
        <tr class="{{ "bright" if config.highlightCountry === stats.countryInfo.iso3 }}">
            <td align="left"><img src="{{ stats.countryInfo.flag }}"  width=30px height=30px/></td>
            <td align="center">{{ stats.country }}</td>
            {% for keys, data in stats.casesInfo %}
                <td align="center">{{ data }}</td>
            {% endfor %}
        </tr>
    {% endfor %}

The data structure looks something the below. So from the data structure below I want to sort by a key in the casesInfo.

myData.push({
            "updated": formatedDate,
            "country": e.country,
            "countryInfo": {
                "iso3": e.countryInfo.iso3,
                "flag": e.countryInfo.flag
            },
            "casesInfo": {
                "cases": e.cases,
                "todayCases": e.todayCases,
                "deaths": e.deaths,
                "todayDeaths": e.todayDeaths,
                "recovered": e.recovered,
                "todayRecovered": e.todayRecovered,
                "active": e.active,
                "critical": e.critical
            }

Is there anyway I can achieve this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!