Javascript String formatArray(a)

Description

Javascript String formatArray(a)


'use strict';/*from   www  .ja  va  2  s  .c o m*/

String.prototype.formatArray = function(a){
 return this.replace(/\{(\d+)\}/g, function(r,e){return a[e];});
};

String.prototype.render = function(obj){
 return this.replace(/\{(\w+)\}/g, function(r,e){return obj[e];});
};



PreviousNext

Related