PROWAREtech

articles » current » javascript » ie11 » ie11-prototype-string-trim

JavaScript: IE11 String.trim() Prototype/Function

Create the String.trim() prototype for Internet Explorer 11.

Still developing for IE11? Well, this prototype is used to remote whitespace from the beginning and end of a string.


if (!String.prototype.trim) {
	String.prototype.trim = function () {
		return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
	};
}

Using the above code snippet:


if (!String.prototype.trim) {
	String.prototype.trim = function () {
		return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
	};
}
alert("     123     ".trim());

PROWAREtech

Hello there! How can I help you today?
Ask any question

PROWAREtech

This site uses cookies. Cookies are simple text files stored on the user's computer. They are used for adding features and security to this site. Read the privacy policy.
CLOSE