Inside Express/EJS templates, what is cleanest way

2019-03-14 10:54发布

I have an Express.js app set up using EJS templates. I successfully looped through an array with classic JS syntax:

<% for (var i = 0; i < myArray.length; i++) { 
    this = myArray[i];
    // display properties of this
} %>

But I'm wondering, is there a cleaner way to do this?

Specifically, can I use Underscore or Lodash to loop through with .each ? thank you

1条回答
Ridiculous、
2楼-- · 2019-03-14 11:23

You can use forEach method

myArray.forEach(function(el, index) {
    // el - current element, i - index
});
查看更多
登录 后发表回答