在Express / EJS模板内部,循环数组的最简洁方法是什么?

时间:2013-04-22 17:43:21

标签: node.js express underscore.js ejs partials

我使用EJS模板设置了Express.js应用程序。我成功地使用经典的JS语法循环数组:

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

但我想知道,有更清洁的方法吗?

具体来说,我可以使用Underscore或Lodash来循环使用.each吗?谢谢

1 个答案:

答案 0 :(得分:61)

您可以使用forEach方法

myArray.forEach(function(el, index) {
    // el - current element, i - index
});
相关问题