Created
September 10, 2012 22:06
-
-
Save wafflesnatcha/3694331 to your computer and use it in GitHub Desktop.
JavaScript: String.trim()
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
/** | |
* Removes whitespace from both ends of the string. | |
* | |
* @returns {String} The trimmed string. | |
*/ | |
if (!String.prototype.trim) { | |
String.prototype.trim = function () { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment