I am trying to replace string with data.replace, its working fine if using hard code or static value. But now i want to replace multiple values with loop but its not working.
My Code:
for(var i = 0; i<words.length; i++){
var r = words[i];
data = data.replace(/\[(\[qid:{r})\]]/g, words[i]);
}
Words contains:
Array [ "hid_1", "hid_2", "hid_6", "hid_7" ]
and my data is:
Site: [[qid:hid_1]]<br>
Block: [[qid:hid_2]]<br>
Nimewo kay la: [[qid:hid_6]]<br>
Latitude: [[qid:hid_7]]
its an HTML content.
i just need variable here:
for(var i = 0; i<words.length; i++){
var r = words[i];
data = data.replace(/\[(\[qid:hid_1)\]]/g, 'test');
//data.replace(/\[(\[qid:{r})\]]/g, 'test');
}