JavaScript and JQuery Essentials Trainin... (53 Blogs)
AWS Global Infrastructure

Front End Web Development

Topics Covered
  • AngularJS (35 Blogs)
  • jQuery UI Development (2 Blogs)
  • The Complete WebDeveloper (40 Blogs)
  • ReactJS (7 Blogs)

How To Implement JavaScript Trim Method?

Published on Aug 08,2019 696 Views
11 / 31 Blog from JavaScript

Dealing with spaces  in the strings you wish to use, can be a tedious task. JavaScript Trim Method lets you deal with this issue. In this article we will be exploring this JavaScript concept in detail.

So let us get started with with this article on JavaScript Trim, let us get familiar to the subject in hand,

JavaScript Trim

Strings are one of the basic concepts of Java programming that we use. A lot of functions are available to manipulate Strings like length(),concat(),indexOf(),charAt() etc. One such function is trim. Trim removes space from the String value and gives us the trimmed string without manipulating the original string.

Space in the sense whitespace, tab etc that are present in front and at the end of string are removed, not the ones that are in between the words of a string. The trim functionality is similar in javascript too. All browsers since IE9+,Opera 10.5+,Firefox 3.5+,Chrome 5+,Safari 5+ support this functionality.

Javascript provides 3 different types of trim functions.

So let us move on with this JavaScript Trim article and see the following function,


As the name indicates, it removes the space present to the left side of the string i.e beginning of the string or leading white spaces.


var string = "Hi, Welcome to Edureka!";


Hi,Welcome to Edureka! 

Next in this article we have trim right function,


As the name indicates, it removes the space present to right side of the string i.e at the end or trailing white spaces.


var string = "Hi, Welcome to Edureka!";


 Hi,Welcome to Edureka! 

So let us move on with this JavaScript Trim article and see the following function,


This removes the space present both at front and back i.e leading and trailing whitespaces.


var string = "Hi, Welcome to Edureka!";


Hi,Welcome to Edureka!      

Note: Trim never removes the spaces in between. It only trims leading and trailing whitespaces. The above examples demonstrates it well.

With this, we have come to the end of our  JavaScript Trim article. I hope you understood the different ways to concatenate or join strings.

Now that you know about JavaScript, check out the Web Development Certification Training by Edureka. Web Development Certification Training will help you Learn how to create impressive websites using HTML5, CSS3, Twitter Bootstrap 3, jQuery and Google APIs and deploy it to Amazon Simple Storage Service(S3). 

Got a question for us? Please mention it in the comments section of “JavaScript Trim” and we will get back to you.


Join the discussion

Browse Categories

Send OTP
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.