Lodash _.padEnd() Method

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:

_.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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

'GFG  '
'1234##'

Example 2:  

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

'GFG---'
'1234'

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.