String.prototype.format() - mkloubert/jsToolbox GitHub Wiki

String.prototype.format([...args]) method

Handles the string as format string and returns the formatted version.

The behaviour is similar to the String.Format() method of the .NET-Framework.

Syntax

String.prototype.format([...args]);

Parameters

Name Type Description
args mixed One or more argument for the format string.

Result

The formatted string.

Examples

// 'MK+TM'
var res1 = '{0}+{1}'.format('MK', 'TM');
// '1*2*3=6'
var res2 = '{1}*{3}*{0}={2}'.format(3, 1, 6, 2);