If you need to simulate @Trim (formula) / fulltrim (LotusScript) in JavaScript (string-only), you can do so with the following function using regular expressions:
function trim(txt)
{
return txt.replace(/(^ +|
+\$)/g,'').replace(/ +/g, ' ');
}