Lodash - times method
Syntax
_.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).
Arguments
n (number) − The number of times to invoke iteratee.
[iteratee=_.identity] (Function) − The function invoked per iteration.
Output
(Array) − Returns the array of results.
Example
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
\>node tester.js
Output
[ '0', '1', '2' ] [ 0, 0, 0, 0 ]
lodash_util.htm
Advertisements