Lodash _.repeat() Method
Lodash _.repeat() method is used to repeat the given string n times.
Syntax:
_.repeat(string, n);
Parameters:
- string: This parameter holds the string to repeat.
- n: n is the number of times to repeat the string.
Return Value:
This method returns the repeated string.
Example 1: In this example, we are repeating the given string the given number of times by the use of the lodash _.repeate() method.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.repeat() method console.log(_.repeat( '#' , 4)); console.log(_.repeat( 'gfg' , 3)); |
Output:
####
gfggfggfg
Example 2: In this example, we are repeating the given string the given number of times by the use of the lodash _.repeate() method.
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.repeat() method console.log(_.repeat( 'w3wiki' , 0)); console.log(_.repeat( '_GFG_' , 3)); |
Output:
''
_GFG__GFG__GFG_
Contact Us