what is the easiest way to trim empty spaces from the end of a string in jquery/javascript?
example:
"my string " should return "my string"
thanks
what is the easiest way to trim empty spaces from the end of a string in jquery/javascript?
example:
"my string " should return "my string"
thanks
jQuery's $.trim() will trim leading and trailing spaces from a string :
There's also the native
trim()method that is supported in newer browsers, and there's a polyfill available on MDN for non-supporting browsers.If for some reason you only want to trim trailing spaces, you can do something like :
to be used as :