formatString

View sourceformatString(string: string, ...args: any[]): string

Replaces numbered placeholders in a string with truthy positional arguments.

Only placeholders made of decimal digits, such as {0} or {12}, are recognized. A missing or falsy argument (undefined, null, false, 0, an empty string, or NaN) leaves its placeholder unchanged. Replacement values are converted to strings by String.prototype.replace.

Examples

formatString('Hello, {0}!', 'Ada') // 'Hello, Ada!'
formatString('Count: {0}', 0) // 'Count: {0}'

Parameters

NameDescriptionDefault
string

String containing numbered placeholders.

—
...args

Values matched to placeholders by zero-based index.

—

Returns

The string with eligible placeholders replaced.