For example : I have a string like that: " Text is text ".
Now i want to use Javascript to remove all space before and ending of that string to have result :
"Text is text".
How can I that with Javascript. Thank for your help.
For example : I have a string like that: " Text is text ".
Now i want to use Javascript to remove all space before and ending of that string to have result :
"Text is text".
How can I that with Javascript. Thank for your help.
Use String.trim (IE 9+ and normal browsers).
" my text ".trim(); // "my text"
To make sure it will work in all browsers you can use a regular expression:
var str, re; str = " my text "; re = /^\s+|\s+$/g; console.log(str.replace(re, '')); String.prototype.trim(), String.trim() will give you TypeError.trim of class String.