Created
November 28, 2014 11:14
-
-
Save kkoziarski/504e234d619ba460593b to your computer and use it in GitHub Desktop.
String.trim - The Good Parts
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
//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