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

This JavaScript tutorial explains how to use the string method called trimEnd() with syntax and examples.

Description

In JavaScript, trimEnd() is a string technique that is used to put off whitespace characters from the end of a string. Whitespace characters include spaces, tabs, etc. Because the trimEnd() technique is a approach of the String object, it have to be invoked through a specific instance of the String class.

Syntax

In JavaScript, the syntax for the trimEnd() approach is:

string.trimEnd();

Parameters or Arguments

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

Returns

The trimEnd() approach returns a string with whitespace characters removed from the end of the string.

Note

The trimEnd() approach does not change the fee of the authentic string. The trimEnd() technique can be aliased as the trimRight() method which additionally eliminates whitespace characters from the proper side or stop of the string.

Example

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

For example:

var totn_string = '   TechOnTheNet   ';

console.log(totn_string.trimEnd());

In this example, we have declared a variable known as totn_string that is assigned the string value of ‘TechOnTheNet’. We have then invoked the trimEnd() method of the totn_string variable to get rid of the whitespace characters from the cease of the string.

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

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

'   TechOnTheNet'

In this example, the trimEnd() method removed the whitespace characters from the end of the string and back a string value of ‘ TechOnTheNet’.