Trim string using javascript No ratings yet.

By | June 19, 2016

You can do this using various techniques. Some of them are as follows:

Method 1: Using Plain Javascript:

You can do it using the simple simple Javascript expression as follows:



Method two: Using trim() function of Jquery:

In order to trim a string, firstly you can use the $.trim() function of Jquery to make the input string neat(removes all newlines, spaces and tabs from the beginning and end of the supplied string).

Since you would be using the $.trim() function of Jquery, don’t forgot to include the library file of Jquery:

And here is a simple solution to this task :



And if you want to truncate a string to nearest white space using javascript, you can refer this article :

Truncating string to nearest white space using Javascript .



Please rate this

2 thoughts on “Trim string using javascript

  1. coupons

    Den Gutschein koennte ich gut gebrauchen, um eine neue Brille zu kaufen und den FIlm dann auch in scharf sehen zu koennen.


Leave a Reply

Your email address will not be published. Required fields are marked *