1

this community has helped me a lot with my work so i decide join to. i have this code :

var empnfill = ["á","é","í","&#243","&#250","&"]; //what i want to replace
var empnfill2 = ["á","é","í","ó","ú","&"]; // for what i want to replace 
var empn;
for(i=0 ; i<empnfill.length; i++)
empn = new RegExp(empnfill[i], "g");
if(job.source_empname.indexOf(empnfill[i])>-1){
job.source_empname = job.source_empname.replace(empn,empnfill2[i]);
    }

job.source_empname is just an object i have in my plataform and contains all the informacion. the problem is im trying to replace all occurrences and isn't working, I used to use this code:

var empnfill = [];
var empnfill2 = [];
for(i=0 ; i<empnfill.length; i++)
  if(job.source_empname.indexOf(empnfill[i])>-1){
    job.source_empname = job.source_empname.replace(empnfill[i],empnfill2[i]);
}

it work fine but just replace the first ocurrence

I thank you in advance to anyone who can help me

  • It’s not clear what you mean by “coincidence”. The code you posted seems to be about replacing HTML entities, yet apparently you’re trying to find “coincdences”, whatever that means. It’s not clear. – Sebastian Simon Aug 05 '16 at 21:12
  • Should not have been marked as duplicate, in my opinion. There is a much better solution than the one for the linked "duplicate" question. See this: https://gist.github.com/CatTail/4174511 – Jared Price Aug 05 '16 at 21:21
  • @JaredPrice Then add an answer to the linked question. – Andrew Marshall Aug 06 '16 at 02:16

0 Answers0