Javascript String replaceAll(str, targetStr)

Description

Javascript String replaceAll(str, targetStr)


String.prototype.replaceAll = function(str, targetStr){
 // var regExp = new RegExp(str, 'g');
 // return this.replace(regExp, targetStr);
 var result = this;
 while(result.indexOf(str) != '-1'){
  result = result.replace(str, targetStr);
 }

 return result;//  w w w .  j  ava2s.  c  o m
}



PreviousNext

Related