Created
September 24, 2019 09:22
-
-
Save qwersk/4dc6821e3598ad1563846c07dd397367 to your computer and use it in GitHub Desktop.
Custom trim function #JS
This file contains hidden or 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
if (!String.prototype.trim) { | |
String.prototype.trim = function () { | |
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | |
}; | |
} | |
var str = " Hello World! "; | |
alert(str.trim()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment