Q:

How set dynamic class in pug?

How do I set a dynamic class in Pug in a loop?
I want to have the same output as below:
.main 
  span.player1
  span.player2
  span.player3
  span.player4

How can I use this loop to implement the code above?
.main 
 each item in [1,2,3,4]
  span.player+item

A:

You could accomplish this with the traditional class attribute:
.main 
  each item in [1,2,3,4]
    span(class="player"+item)

In Pug, doing p.some-class is equivalent to p(class="some-class"), as that is what it compiles down to anyway, when transformed into HTML.

