Trim in Javascript

TRIM IN JAVASCRIPT

 

JavaScript supports a large number of functions, the trim function is present in one of them, the trim is a JavaScript function that is used for the space removed from the start and end. This removes the beginning and end of the string's white space

 

JavaScript trim doesn't take any argument to call, it always returns a new string without any leading and trailing white space.

 

Example 1: -

//  TODO : DEFINE VARIABLE
  var x = “ gomehere      ”;  
 // TODO : REMOEV SPACE FROM LAST OF THE STRING
var x = x.trim();   
 // TODO : SEE RESULT AFTER JAVASCRIPT TRIM
console.log(x);   

Output

Gomehere

Example 2: -

 //  TODO : DEFINE VARIABLE

var x = “       gomehere”;
 // TODO : REMOEV SPACE FROM START OF THE STRING

var x = x.trim();
 // TODO : SEE RESULT AFTER JAVASCRIPT TRIM

console.log(x);

Output

Gomehere


About author

Author:- Mukesh Pant

Mukesh Pant

Founder of GOMEHERE and exploring new ideas in multiple areas like technology, programming, travel, sport, utility, and many more for the audience to solve their problems. Also, keep in touch by email mrpant90@gmail.com




Leave a Comments

Scroll to Top