Lodash _.trimStart() Method

Lodash _.trimStart() method removes leading white spaces or specified characters from the given string.

Syntax:

_.trimStart(string, chars);

Parameters:

  • string: This parameter holds the string to be trimmed.
  • chars: This parameter holds the charset to be specifically trimmed.

Return Value:

This method returns a trimmed string.

Example 1: In this example, we are getting a trimmed string by the use of the lodash _.trimStart() method.

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
let str = "   Beginner-for-Beginner   ";
 
// Using _.trimStart() method
console.log(_.trimStart(str));


Output:

"Beginner-for-Beginner   "

Example 2: In this example, we are getting a trimmed string by the use of the lodash _.trimStart() method.

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
let str = "----w3wiki----";
 
// Using _.trimStart() method
console.log(_.trimStart(str, "-"))


Output:

"w3wiki----"

Note: This will not work in normal JavaScript because it requires the lodash library to be installed and can be installed using npm install lodash.


Contact Us