Created
May 15, 2014 12:46
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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