Skip to content

Instantly share code, notes, and snippets.

@alordiel
Created June 1, 2017 08:32
Show Gist options
  • Save alordiel/f15c8e2a7ac90c97f4d1b5902eafe812 to your computer and use it in GitHub Desktop.
Save alordiel/f15c8e2a7ac90c97f4d1b5902eafe812 to your computer and use it in GitHub Desktop.
JS: using array of elements to seach and array of element for replace in standard replace function
var search = ['Á','Â','Á','Ã','É','Ê','Í','Ó','Ô','Õ','Ú','Ç','á','â','ã','é','ê','í','ó','ô','õ','ú','ç','À','à']
var replace= ['a','a','a','a','e','e','i','o','o','o','u','c','a','a','a','e','e','i','o','o','o','u','c','a','a'];
var string = 'Ele eé um homem';
for (var i = 0; search.length > i; i++) {
if (string.indexOf(search[i]) != -1) {
string = string.replace(search[i],replace[i]);
}
}
console.log(string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment