Friday, September 5, 2025
HomeLanguagesJavascriptLodash _.repeat() Method

Lodash _.repeat() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. 

The _.repeat() method is used to repeat the given string n times.

Syntax:

_.repeat(string, n)

Parameters: This method accepts two parameters as mentioned above and described below:

  • 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:

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:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
      
// Use of _.repeat() method 
console.log(_.repeat('neveropen', 0)); 
console.log(_.repeat('_GFG_', 3));


Output:

''
_GFG__GFG__GFG_
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6636 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11865 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6703 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS