Skip to content

Instantly share code, notes, and snippets.

@wafflesnatcha
Created September 10, 2012 22:06
Show Gist options
  • Save wafflesnatcha/3694331 to your computer and use it in GitHub Desktop.
Save wafflesnatcha/3694331 to your computer and use it in GitHub Desktop.
JavaScript: String.trim()
/**
* 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