function maskify(cc) { var dd = cc.toString(); var hash = dd.replace((/./g), '#'); for (var i = (hash.length - 4); i < hash.length; i++) { hash[i] = dd[i]; } return hash; }
I'm trying to replace all # characters except for the last 4. Why doesn't it work?
#
To replace a character in a string with a given index, hash[i] = dd[i] does not work. Strings are immutable in Javascript. See How to replace a character in a specific index in JavaScript? for some tips on this.
hash[i] = dd[i]
You can do it as follows:
dd.replace(/.(?=.{4,}$)/g, '#');
var dd = 'Hello dude'; var replaced = dd.replace(/.(?=.{4,}$)/g, '#'); document.write(replaced);
Source: https://habr.com/ru/post/1242493/More articles:Java image saturation change - javaPrivate naming convention in the official Angular 2 http tutorial - angularjsBinary Search Complete Status - algorithmAvoid code duplication when reusing multiple value constructor templates - haskellhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1242492/boost-spirit-istreamiterator-consumes-too-much-from-stream&usg=ALkJrhj10fC-1JEJe6XiV7fniHkik8ljfQWhat is the difference between response.body () and the object returned by the callback? - spark-javaIs there an alternative to npm-check-updates module? - javascriptFailed to verify first certificate - pythonXmppFramework I get KissXml error - iosIOS hardware volume buttons - press and hold - iosAll Articles