I have an object, and inside my HTML I use tags of the form [itemkey] to refer to the value of the itemkey property of that object, and want to replace these tags with their values. My JavaScript code looks like this:
_.forEach(objectItem,function(val,key){
var re = new RegExp('\[' + key +'\]','g');
htmlDump = htmlDump.replace(re,val)
});
But it does not work. What is wrong?
RegExpconstructor. Usenew RegExp('\\[' + key + '\\]');keycontain any special characters?new RegExp(key);htmlDumpbeing replaced in the next iteration.