Pug (Jade) Tutorial #6 - For/Each Loop - Iterate over Arrays and Objects

preview_player
Показать описание
By using the each/for loop in Pug, you are able to easily iterate over an iterable object such as an array or object and then render HTML accordingly, having access to both the key and value of the respective items. In Pug, the each and the for loop do the same thing except they are just aliases for each other, either one will work.

In this video I take you through the each loop, with examples of an array and also an object. There is also the 'else' keyword which runs whenever there are no items to iterate over.

For your reference, check this out:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Pretty cool as PUG makes things easier!

gustavofreitas
Автор

hi, thanks for the video! not sure if you got my message, but how can I convert pugs' "each val in values" into JS? I need to rewrite it in JS only, and have no idea : maybe through forEach? but still nothing works

meramod
Автор

CanI define an array objects variable in Pug, just the same with JSON ?

photranthi
Автор

how about if i have array of arrays like fetching data from database and sending it to view.

SharadMishraJigSaw