I would like to know how to replace the accented characters and symbols in a object using javascript.
I have tried the below method but I would like to know if there is alternative way to do,
var result = obj.countries.forEach(e=>replaceData(obj));
function replaceData(obj){
var in_chrs = 'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',
out_chrs = 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY',
chars_rgx = new RegExp('[' + in_chrs + ']', 'g'),
transl = {}, i,
lookup = function (m) { return transl[m] || m; };
for (i=0; i<in_chrs.length; i++) {
transl[ in_chrs[i] ] = out_chrs[i];
}
return s.replace(chars_rgx, lookup);
}
var obj ={
"contries":{
"CI": "côte-d’ivoire",
"RE": "réunion",
"AG": "antigua & barbuda",
"SG": "singapore",
"TH": "thailand",
"US": "united-states"
}
}
Expected Output:
{
"contries":{
"CI": "cote divoire",
"RE": "reunion",
"AG": "antigua and barbuda",
"SG": "singapore",
"TH": "thailand",
"US": "united states"
}
}