A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-string-trimstart-and-trimleft-method/ below:

JavaScript String trimStart() and trimLeft() Method

JavaScript String trimStart() and trimLeft() Method

Last Updated : 12 Jul, 2025

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 = " GeeksforGeeks     ";
    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
"GeeksforGeeks     "
"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 = " GeeksforGeeks     ";
    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
"GeeksforGeeks     "
"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:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4