Lodash - times 方法
语法
_.times(n, [iteratee=_.identity])
调用 iteratee n 次,返回每次调用结果的数组。 iteratee 使用一个参数调用;(索引)。
参数
n(数字) − 调用 iteratee 的次数。
[iteratee=_.identity](函数) − 每次迭代调用的函数。
输出
(数组) −返回结果数组。
示例
var _ = require('lodash'); console.log(_.times(3, String)); console.log(_.times(4, _.constant(0)));
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
[ '0', '1', '2' ] [ 0, 0, 0, 0 ]