by @kodeazy

JavaScript How to replace all occurances of sub string with desired string?

Home » JQuery » JavaScript How to replace all occurances of sub string with desired string?
  • we use replaceAll() function to replace all occurances of a string.

    var str="test 123 test 123 test 123 test 123";
    str=str.replaceAll("123","45");
    console.log(str);

    Output:

    test 45 test 45 test 45 test 45