Who can tell me what's wrong??? This was suposed to eliminate spaces at the beginind and at the end of a string.If there are two spaces they should be eliminated. But why the string "result" remains unchanged?
Why not just use something like this? str = str.replace(/^\s*|\s*$/g,""); Code (markup): Not had a long look at your code but what I think you doing is are setting result to a single character each time, and not appending the string.
"That shit" is a regular expression that removes all excess spaces at the start and end of the str variable.