Using String trimStart() method to coding in Javascript/JS

This JavaScript tutorial explains how to use the string approach referred to as trimStart() with syntax and examples.

Description

In JavaScript, trimStart() is a string method that is used to cast off whitespace characters from the start of a string. Whitespace characters include spaces, tabs, etc. Because the trimStart() approach is a approach of the String object, it have to be invoked thru a precise occasion of the String class.

Syntax

In JavaScript, the syntax for the trimStart() method is:

string.trimStart();

Parameters or Arguments

There are no parameters or arguments for the trimStart() method.

Returns

The trimStart() method returns a string with whitespace characters removed from the begin of the string.

Note

The trimStart() approach does no longer alternate the cost of the authentic string. The trimStart() method can be aliased as the trimLeft() technique which also gets rid of whitespace characters from the left side or start of the string.

Example

Let’s take a seem to be at an instance of how to use the trimStart() method in JavaScript.

For example:

var totn_string = '   TechOnTheNet   ';

console.log(totn_string.trimStart());

In this example, we have declared a variable called totn_string that is assigned the string price of ‘TechOnTheNet’. We have then invoked the trimStart() technique of the totn_string variable to eliminate the whitespace characters from the start of the string.

We have written the output of the trimStart() approach to the web browser console log, for demonstration purposes, to exhibit what the trimStart() approach returns.

The following will be output to the internet browser console log:

'TechOnTheNet   '

In this example, the trimStart() method eliminated the whitespace characters from the start of the string and lower back a string value of ‘TechOnTheNet ‘.