Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Function for masking the character

<script>
    // Function for masking the character 
    function MaskCharacter(str, mask, n = 1) {
  
        // Slice the string and replace with
        // mask then add remaining string
        return ('' + str).slice(0, -n)
            .replace(/./g, mask)
            + ('' + str).slice(-n);
    }
  
    // Number that we want to mask 
    var num = 12345678;
  
    // Convert number into string
    var str = num.toString();
  
    // Call function without giving value of n
    console.log(MaskCharacter(str, '#'));
  
    // Call function with value of n
    console.log(MaskCharacter(str, '#', 2));
</script>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Function #masking #character
ADD COMMENT
Topic
Name
1+4 =