Skip to content
Related Articles

Related Articles

Lodash _.repeat() Method
  • Last Updated : 09 Sep, 2020

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
      
// Use of _.repeat() method 
console.log(_.repeat('#', 4)); 
console.log(_.repeat('gfg', 3));

chevron_right


Output:

####
gfggfggfg

Example 2:  

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

''
_GFG__GFG__GFG_

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :