- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
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
To Continue Learning Please Login
Login with Google