Javascript String replaceSpaces()

Description

Javascript String replaceSpaces()


String.prototype.replaceSpaces = function() {
  var length = this.length;
  for(var i = 0; i < length; i++) {
    if(this[i] == ' ') {
      this[i] = "%20"
    }// www . java2  s  .c o  m
  }
  return this.toString();
}


console.log("This is my Name".replace(/ /ig, '%20'));



PreviousNext

Related