Replace all chars with #, except for last 4
If you find the solution, try this trick
function maskify(cc) {
return cc.slice(0, -4).replace(/./g, '#') + cc.slice(-4);
}
You could do it like this:
dd.replace(/.(?=.{4,}$)/g, '#');
var dd = 'Hello dude';
var replaced = dd.replace(/.(?=.{4,}$)/g, '#');
document.write(replaced);