Javascript String rep(x, y)

Description

Javascript String rep(x, y)


// replace in string function

String.prototype.rep = function(x, y){
 var string = this; 
 return string.split(x).join(y); 
}

var str = 'This is the best time of your life best'

var result = str.rep('best', 'worst'); 

console.log(result);/*  w  ww .j a  v a2  s . c o m*/



PreviousNext

Related