Answers for "You can also use the replace solution above to add a trim function to the JavaScript String.prototype:"

0

You can also use the replace solution above to add a trim function to the JavaScript String.prototype:

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());
Posted by: Guest on April-23-2021

Code answers related to "You can also use the replace solution above to add a trim function to the JavaScript String.prototype:"

Browse Popular Code Answers by Language