Replacing alternate 2 digits of a number with dot in Polymer 3

荒凉一梦 提交于 2019-12-25 03:19:21

问题


I want to replace alternate 2 digit of a number with a dot in polymer 3. I tried something but it is not working as i wanted. Please help.

before masking : 56789012 after masking : 5..8..1.


回答1:


Here you go have fun with it:

var maskingfield = function (str) {
    var out = "";
    for (var j = 0; j < str.length; j++) {
        if (j % 3 === 1 || j % 3 === 2) {
            out += '.';
        } else {
            out += str[j];
        }
    }
    return out;
} 

Calling : maskingfield("56789012") will give you "5..8..1."



来源:https://stackoverflow.com/questions/56747620/replacing-alternate-2-digits-of-a-number-with-dot-in-polymer-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!