replace string in js

علی ذوالفقار
1402/03/16 10:36:33 (129)
var myStr = 'abs is here!'
Method 1:
myStr = myStr.replace(/abc/g, "Ali-Zolfaghar");

Method 2:
myStr = myStr.split("abc").join("Ali-Zolfaghar");

Method 3:
myStr = myStr.replace(new RegExp("abc", "g"), "Ali-Zolfaghar");

Method 4:
while(str.includes("abc")){
   myStr = myStr.replace("abc", "Ali-Zolfaghar");
}
Back