Javascript String format(args, index)

Description

Javascript String format(args, index)


// replaces {..} with values in array
String.prototype.format = function(args, index) {
  return this.replace(/{(\w+)}/g, function(match, number) {
    return typeof args[index[number]] != 'undefined'
      ? args[index[number]]// w ww.  j  a  va 2  s .co m
      : match
    ;
  });
};



PreviousNext

Related