Skip to main content

Replace the first given number of characters of a string with another character

JavaScript version

const mask = (str, num, mask) => `${str}`.slice(num).padStart(`${str}`.length, mask);

TypeScript version

const mask = (str: string, num: number, mask: string): string => `${str}`.slice(num).padStart(`${str}`.length, mask);

Examples

mask(1234567890, 3, '*'); // ***4567890

Comments