Open In App

Lodash _.padStart() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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

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

Example 1: In this example, we are adding the given value to the string by using the lodash _.padStart() method.

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: In this example, we are adding the given value to the string by using the lodash _.padStart() method.

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'

Last Updated : 30 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads