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

110
Views
Pug increase the number 'inside' array name

I'm using PUG and I have arrays as below

-let filter0 = ['Category', 'Brand', 'Price', 'Color']
-let filter1 = ['Category 1', 'Category 2', 'Category 3']
-let filter2 = ['Brand 1', 'Brand 2']
-let filter3 = ['Price 1', 'Price 2']
-let filter4 = ['Color 1', 'Color 2']

filter0 defines my titles.

The rest (filter#) defines sub categories of each title.

I want to increase the name of array in every loop same as class names.

each val, index in filter0
  input(class='toggle' id='toggle'+index type='checkbox')
  label.title(for='toggle'+index)
    = val
  .content
    each val, index in filter1 // This should be filter+index so the result can be filter1,filter2 etc.
      ul
        li
          input(class='checkbox' id='checkbox-'+index type='checkbox' value='value'+index)
          label(for='checkbox-'+index)= val

Is this possible? Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For anyone who might want to see the solution for some reason :P Thanks @AminTaghikhani

var filter = {
0: ['Category', 'Brand', 'Price', 'Color'],
1: ['Category 1', 'Category 2', 'Category 3'],
2: ['Brand 1', 'Brand 2'],
3: ['Price 1', 'Price 2'],
4: ['Color 1', 'Color 2']
}
each x, y in filter[0]
  input(class='toggle' id='toggle'+y type='checkbox')
  label.title(for='toggle'+y)
    = x
  .content
    each a, b in filter[1+y]
      ul
        li
          input(class='checkbox' id='checkbox-'+b+y type='checkbox' value='value'+b+y)
          label(for='checkbox-'+b+y)= a
about 4 years ago · Juan Pablo Isaza Report
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!