Friday, September 27, 2024
Google search engine
HomeLanguagesJavascriptLodash _.trimEnd() Method

Lodash _.trimEnd() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.trimEnd() method is used to remove trailing white spaces or specified characters from the end of the given string.

Syntax:

_.trimEnd( string, chars )

Parameters: This method accepts two parameters as mentioned above and described below:

  • string: It is the string that has to be trimmed.  The default value is an empty string.
  • chars: It is a set of characters that have to be trimmed from the string. It is an optional parameter. The default value is a whitespace.

Return Value: This method returns the trimmed string.

Example 1:

Javascript




// Defining Lodash variable 
const _ = require('lodash'); 
  
// The string to trim
var str = "   Geeks-for-Geeks   ";
  
// Using _.trimEnd() method
console.log(_.trimEnd(str));


Output:

"   Geeks-for-Geeks"

Example 2:

Javascript




// Defining Lodash variable 
const _ = require('lodash'); 
  
// The string to trim
var str = "----neveropen----";
  
// Using _.trimEnd() method
// with specific characters to trim
console.log(_.trimEnd(str, "-"))


Output:

"----neveropen"
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments