JSFiddle - React, Tailwind, and code Playground

by Annie Lagang

HTML

<div style="color:#ff0200;font-size:14px;" id="VoucherBookingDeptDateInvalid">The departure date of your booking is invalid. Kindly choose another departure date on or before {0} {1} {2} {3}.</div>

JavaScript

$(function(){
  var id = 'VoucherBookingDeptDateInvalid';
  var newContent = ['date', 'woot', 'ano', 'sabi'];
  
    // get error message via errorId
    var obj = $('#'+ id);
                                        
    var tempContent = obj.text();
    tempContent = String.format(tempContent, newContent);   
    obj.text(tempContent); 
});

// SOURCE: http://stackoverflow.com/a/4673436/906815
String.format = function(format) {
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[0][number] != 'undefined'
        ? args[0][number] 
        : match
      ;
    });
};