OneCompiler

javascript method to replace word with new one

146


function replaceText(inputstring){
let result;
//1st method reg expression

result= string.replace(/bug/g ,"flower");

// 2nd method js bulit in method

result = string.replaceAll("bug","flower");

//3rd method using while loop
while(string.include("bug")){
result = string.replace("bug","flower");
}
console.log(result);
return result;
}

replaceText("toboybugjoby");
replaceText("zxxzbugjobugnoggy");