Saturday, December 13, 2025
HomeLanguagesJavascriptLodash _.padStart() Method

Lodash _.padStart() Method

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

Syntax:

_.padStart( [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 examples illustrate the Lodash _.padStart() method in JavaScript:

Example 1:

Javascript




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


Output:

'  GFG'
'##1234'

Example 2:  

Javascript




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


Output:

'---GFG'
'1234'
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7200 POSTS0 COMMENTS
Thapelo Manthata
6897 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS