Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.padEnd() Method

  • Last Updated : 09 Sep, 2020

The _.padEnd() method is used to pad a string with another string until it reaches the given length. The padding is applied from the right end of the string. Padding characters are truncated if they exceed the length.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

_.padEnd( [string = ''], [length = 0], [chars = ' '] )

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

  • string: This parameter holds the string to the pad.
  • length: This parameter holds the length of the pad.
  • chars: This parameter holds the string used as padding.

Return Value: This method returns the padded string.



Below example illustrate the Lodash _.padEnd() method in JavaScript:

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.padEnd() method 
console.log(_.padEnd('GFG', 5)); 
console.log(_.padEnd('1234', 6, '#')); 

Output:

'GFG  '
'1234##'

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
       
// Use of _.padEnd() method 
console.log(_.padEnd('GFG', 6, '-')); 
console.log(_.padEnd('1234', 3, '#')); 

Output:

'GFG---'
'1234'

My Personal Notes arrow_drop_up
Recommended Articles
Page :