Saturday, October 11, 2025
HomeLanguagesJavascriptJavaScript String trimStart() and trimLeft() Method

JavaScript String trimStart() and trimLeft() Method

This article demonstrates trimEnd and trimRight methods of JavaScript string. Both methods are used to perform the same task and their implementation is shown below:

JavaScript trimStart() method:

The trimStart() method in JavaScript is used to remove whitespace from the beginning of a string. The value of the string is not modified in any manner, including any whitespace present after the string. 

Syntax:

string.trimStart();

Return Value:

It returns the final string that is stripped out of all the white space in the beginning. 

Example: This example implements the trimStart() method. 

Javascript




// Function to implement trimStart method
function trimString() {
 
    // Input strings
    str1 = " neveropen     ";
    str2 = "Hello There! ";
     
    // Implementation of trimStart method
    trimmed_out = str1.trimStart();
    trimmed_out2 = str2.trimStart();
 
    // Display output
    console.log('"' + trimmed_out + '"');
    console.log('"' + trimmed_out2 + '"');
}
 
// Function call
trimString()


Output

"neveropen     "
"Hello There! "

JavaScript trimLeft() method:

The trimStart() method has an alias which is the trimLeft() method. It performs exactly the same function as the trimStart() method. 

Syntax:

string.trimLeft();

Return Value:

It returns the final string that is stripped out of all the white space in the beginning. 

Example: This example implements the trimLeft() method. 

Javascript




// Function to implement trimLeft method
function trimString() {
 
    // Input strings
    str1 = " neveropen     ";
    str2 = "Portal ";
 
    // Implementation of trimLeft method
    trimmed_out = str1.trimLeft();
    trimmed_out2 = str2.trimLeft();
 
    // Display output
    console.log('"'
        + trimmed_out + '"');
    console.log('"'
        + trimmed_out2 + '"');
}
 
// Function call
trimString()


Output

"neveropen     "
"Portal "

We have a complete list of Javascript Strings, to check those please go through the Javascript String Complete reference article.

Supported Browsers: The browsers supported by trimStart() method are listed below:

  • Google Chrome
  • Firefox
  • Edge
  • Safari
  • Opera
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS