JavaScript Remove Whitespace from Start/Beginning of String

JavaScript Remove Whitespace from Start/Beginning of String

To remove whitespace from beginning of string javascript; In this tutorial, you’ll learn how to remove whitespace from beginning/starting of string javascript JavaScript String trimStart() method.

Sometimes, you work with javascript strings and you want to remove whitespaces from the beginning of the string, hence this tutorial is helpful for you.

JavaScript String.trimStart()

The javascript string trimStart() method is used to remove the whitespace characters from the beginning of a string.

Note that, The trimLeft() method is an alias of the trimStart() method.

If you want to remove whitespace characters from the end of string, you can use js trimEnd() method.

Syntax of javascript string trimStart() method is following:

let str1 = str.trimStart();

Here,

  • The trimStart() method doesn’t change the given string.

Example: javascript trimStart() method

The following example demonstrates, how to remove whitespace characters from the beginning of a given string using trimStart(), see the following example:

let str = '   JavaScript programming  ';
let result = str.trimStart();

console.log({ result });

Output:

{result: "JavaScript programming  "}

Conclusion

In this tutorial, you have learned how to remove whitespace characters from the beginning of string using the js trimStart() method.

Recommended JavaScript Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *