Underscore.JS times方法
语法
_.times(n, iteratee, [context])
times方法调用iteratee函数n次。它还将索引传递给iteratee函数。参见以下示例 −
示例
var _ = require('underscore');
//Example: Check if times method calls a function 3 times
_.times(3, function(index){console.log(index)});
将上述程序保存在 tester.js 文件中。运行以下命令执行此程序。
命令
>node tester.js
输出
0
1
2