Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Created November 28, 2014 11:14
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 kkoziarski/504e234d619ba460593b to your computer and use it in GitHub Desktop.
Save kkoziarski/504e234d619ba460593b to your computer and use it in GitHub Desktop.
String.trim - The Good Parts
//JavaScript lacks a method that removes spaces from the ends of a string.
//That is an easy oversight to fix:
String.method('trim', function ( ) {
return this.replace(/^\s+|\s+$/g, '');
});
document.writeln('"' + " neat ".trim( ) + '"');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment