Skip to content

Instantly share code, notes, and snippets.

@alisterlf
Created August 27, 2012 18:10
Show Gist options
  • Star 58 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save alisterlf/3490957 to your computer and use it in GitHub Desktop.
Save alisterlf/3490957 to your computer and use it in GitHub Desktop.
JAVASCRIPT:Remove Accents
function RemoveAccents(strAccents) {
var strAccents = strAccents.split('');
var strAccentsOut = new Array();
var strAccentsLen = strAccents.length;
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
} else
strAccentsOut[y] = strAccents[y];
}
strAccentsOut = strAccentsOut.join('');
return strAccentsOut;
}
@alisterlf
Copy link
Author

If your goal is to sort a list of strings, disregarding accents

['André', 'Álister', 'alan'].sort(new Intl.Collator('pt-BR').compare)

Or just to be safe

['André', 'Álister', 'alan'].sort(new Intl.Collator('pt-BR', {sensitivity:'base'}).compare)

@NicolasPlanas1998
Copy link

Other variant could be..
const removeAccents = (str) => { return str .toLowerCase() .normalize("NFD") .replace(/[\u0300-\u036f]/g, ""); };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment