Mask String

Mask a string showing only the last few characters, useful for credit cards or SSNs.

Code

Utilities
str.slice(-visibleChars).padStart(str.length, maskChar);

Parameters

The string to mask.

Number of characters to show at the end.

Character to use for masking.

Browser·fetch() may be limited by CORS

More JavaScript Snippets