Trim in JavaScript

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.   
  9. function testTrim() {  
  10.     var myString = " Test Trim ";  
  11.     alert(trim(myString));