Struggling to track down the issue of finding and replacing a text string, but encountering problems when trying to reference a variable. Oddly enough, everything seems to work perfectly if I manually input the number instead of using a variable.
An error message pops up saying: 'missing : after property id' whenever I attempt to refer to a variable:
var text = "section-1 section_1 section[1]";
var cloneCount = 1;
var cloneUp = 2;
var array = {
"section-"+cloneCount:"section-"+cloneUp,
"section_"+cloneCount:"section_"+cloneUp,
"section\\["+cloneCount:"section\[" + cloneUp
};
for (var val in array) {
text = text.replace(new RegExp(val, "gi"), array[val]);
alert(text);
}
Any help or advice would be greatly appreciated!