将单词中的所有字母替换为js中的*

I'm*_*hin 3 javascript regex replace

我需要创建一个javascript函数替换一个单词的所有字母为星号*.它应该替换词hello123********.如何才能做到这一点 ?

Nea*_*eal 15

使用str.replace(...).

关于互联网的许多例子:-D

例如:

str.replace('foo', 'bar');
Run Code Online (Sandbox Code Playgroud)

或者在你的情况下:

str.replace(/./g, '*');
Run Code Online (Sandbox Code Playgroud)


UpH*_*lix 6

你可以这样做:

'hello123'.replace(/./g, '*');
Run Code Online (Sandbox Code Playgroud)