I need to create a javascript function that replaces all letters of a word to an asterisk *
.It should replace the word hello123
to ********
. How can this be done ?
You can just do:
'hello123'.replace(/./g, '*');
Use str.replace(...)
.
Many examples on the interwebs :-D
For example:
str.replace('foo', 'bar');
Or in your case:
str.replace(/./g, '*');
Try this link How to replace all characters in a string using JavaScript for this specific case: replace . by _
var s1 = s2.replace(/\S/gi, '*');
which will replace anything but whitespace or
var s1 = s2.replace(/./gi, '*');
which will replace every single character to *
even whitespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With