Skip to content

Instantly share code, notes, and snippets.

@tahirm
Created May 15, 2014 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tahirm/76e3da81bd49080a972a to your computer and use it in GitHub Desktop.
Save tahirm/76e3da81bd49080a972a to your computer and use it in GitHub Desktop.
Trim function for strings. If native .trim is available it uses that otherwise trim the string manually. #js #trim #string
//trim string
function trim(str){
return String.prototype.trim ? str.trim() : String(str).replace(/^([\s]*)|([\s]*)$/g, '');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment