Remove accents from a string in JavaScript

Let's assume that we want to remove the accents of a word using JavaScript:

javascript
// Defining word with accents
let example = 'Érík Martín';

// Defining accents and normal chars
let accents = 'ÀÁÂÃÄÅĄĀāàáâãäåąßÒÓÔÕÕÖØŐòóôőõöøĎďDŽdžÈÉÊËĘèéêëęðÇçČčĆćÐÌÍÎÏĪìíîïīÙÚÛÜŰùűúûüĽĹŁľĺłÑŇŃňñńŔŕŠŚŞšśşŤťŸÝÿýŽŻŹžżźđĢĞģğ';
let normal  = 'AAAAAAAAaaaaaaaasOOOOOOOOoooooooDdDZdzEEEEEeeeeeeCcCcCcDIIIIIiiiiiUUUUUuuuuuLLLlllNNNnnnRrSSSsssTtYYyyZZZzzzdGGgg';

// Defining entries as a pair of key, value => [[À, A], [Á, A] ... [ğ, g]]
let entries = [...accents].map((c,i) => [accents[i], normal[i]]);

// Building the object
let accentsNormalObject = Object.fromEntries(entries);

// Transforming the word
let result = [...example].map(c => accentsNormalObject[c] || c).join('');

console.log(result);
// Erik Martin

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.