Remove character from string multiple times
This question already has an answer here:
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, '');
下一篇: 从字符串中多次删除字符