The String.trimStart()
method removes white spaces from the start of a string in JavaScript. White space characters include spaces, tabs, the carriage return, etc.
The trimStart()
method is a method of the string
object and hence must be called from an instance of a string
.
It does not change the value of the original string.
Note:
trimLeft()
is an alias of thetrimStart()
method and removes trailing white space characters from the left side of the string.
string.trimStart();
string.trimStart()
returns a new string with the starting white spaces removed.
var example_string = " This is the example string \t";console.log(`With starting white-spaces: "`+example_string+ `"`);console.log(`Without starting white-spaces: "`+example_string.trimStart()+ `"`);
The code above shows how the trimStart()
method is used. As we can see, the string without starting white spaces does not contain any white spaces to its left, while the white spaces to the right are preserved.
Free Resources