Last Updated: February 25, 2016
·
2.438K
· jasonseney

Add Javascript String.trim() Support for Older Browsers

String.prototype.trim = typeof (String.prototype.trim) != "undefined" ?
    String.prototype.trim :
    function() { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); };

Most newer browsers support " foobar ".trim() --> "foobar", however older browsers (IE 7 etc) need a little help. :)

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside