Javascript: remove trailing spaces only
<p>Can anyone help me on how to remove trailing spaces in JavaScript. 
I want to keep the leading spaces as is and only remove trailing spaces.<br/>
EG: <code>'    test    '</code> becomes <code>'    test'</code>.
Seems like pretty simple but I can't figure it out. </p>

<p>PS: I am pretty sure I can't be the first one to ask this but I can't find an answer in SO. Also, I am looking for JavaScript solution. I am not using jQuery.</p>