Another JavaScript function for trim a string from white space

 

Thanks Joules  left a comment to let me konw that the language attribute for the script tag is deprecated (the article trim a string from white space by JavaScript function ).I wrote another javascript function for trim a string from white space at the front.(It will need some change for RTrim and Trim),I don’t konw there is faster way than below,if you know tell me pls.

 

function LTrim(str) {

var i;

var len = str.length;

? for( i=0; i<len; i++ )

{

if( str.charCodeAt(i) == 160 )

{

str = str.substring(1, str.length );

i–;

len–;

}

else

{

break;

}

}

 

return str;

}

comment:160 is the char code for white space.