In JavaScript, there is no trim method. But below i have created a simple trim method which removes the leading and the trailing spaces from the string.
  1. function trim(str) {
  2. str = str.replace(/^s+/, '')
  3. for (var i = str.length; i--;)
  4. if (/S/.test(str.charAt(i)))
  5. return str.substring(0, ++i)
  6. return str
  7. }
  8. function testTrim() {
  9. var myString = " Test Trim ";
  10. alert(trim(myString));
  11. }