Lodash times method
语法
_.times(n, [iteratee=_.identity])
Invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with one argument; (index).
参数
n (number) − The number of times to invoke iteratee.
[iteratee=_.identity] (Function) − The function invoked per iteration.
输出
(Array) − Returns the array of results.
实例
var _ = require('lodash');
console.log(_.times(3, String));
console.log(_.times(4, _.constant(0)));
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出
[ '0', '1', '2' ]
[ 0, 0, 0, 0 ]