Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 替换字符串中的所有匹配项
我的代码:
alert('111'.replace('1','2'));
它给出的结果为211。但我需要结果为222.
211
222
为了替换所有出现的事件,您可以使用带有(即全局)标志的正则表达式:g
g
"111".replace(/1/g, "2");