Reading time: < 1 minute
To remove accents (diacritics) from a String using Javascript, follow these steps:
We have the following String:
var text = "Camión";
To remove punctuation marks, we need to use the following function (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize):
function stripAccents(s) { return s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); }
This way, when using the function, we can remove the accents:
var text = stripAccents("Camión"); function stripAccents(s) { return s.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } // returns "Camion"