Created
June 1, 2017 08:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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