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
underscorejs_utilities.htm
广告
© . All rights reserved.