Lodash _.times() method Invokes the iteratee n times, returning an array of the results of each invocation. The iteratee is invoked with one argument.
Syntax:
_.times(n, iteratee);
Parameters:
- n: The number of times to invoke iteratee function.
- iteratee: The function which is invoked per iteration.
Return Value:
It Returns the array of results.
Example 1: In this example, we are printing the 5 times String by the use of the lodash _times() method.
Javascript
const _ = require( "lodash" );
let gfg = _.times(5, String);
console.log(gfg);
|
Output:
["0", "1", "2", "3", "4"]
Example 2: In this example, we are printing the 3 times constant by the use of the lodash _times() method.
Javascript
const _ = require( "lodash" );
let gfg = _.times(3, _.constant(5));
console.log(gfg);
|
Output:
[5, 5, 5]
Last Updated :
31 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...