Remove character from string multiple times

This question already has an answer here:

  • How to replace all occurrences of a string in JavaScript? 41 answers

  • Try like this with a global replacement: by /g flag on replace()

    Where, g is global case-sensitive replacement

    var string  = '200.00 EUR, 33.33 EUR, 100.95 EUR, 300 EUR';
    string = string.replace(/ EUR/g, '');
    console.log(string);

    You can use regular expression to replace the string. Keep in mind string are immutable so original string will be unchanged.

    var str = "200.00 EUR, 33.33 EUR, 100.95 EUR, 300 EUR";
    var str1 = str.replace( /s*EUR/g, "");
    console.log(str1);

    简单, str.replace(/EUR/g, '');

    链接地址: http://www.djcxy.com/p/16850.html

    上一篇: string.replace()不会取代ALL

    下一篇: 从字符串中多次删除字符