Skip to main content

How to ignore accented letters in javascript? [duplicate]

I have a javascript code as shown below in which Line A prints the following output at console.

const megaList = sortedMegaList.reduce((r, e) => {
    let group = e.title[0];  // Line B
    console.log(group);   // Line A
}, {});

o/p at console:

B
C
D
E
É
G
H
I
L

What I want achieve is I don't want to show accented letters in the o/p above.

This is what I have tried in the code below. At Line B, I have made the following change:

const megaList = sortedMegaList.reduce((r, e) => {
    let group = e.title[0].normalize('NFD').replace(/[\u0300-\u036f]/g, "");  // Line B
    console.log(group);   // Line A
}, {});

After changes at Line B, its ignoring all accented letters and Line A doesn't print any accented letters in the o/p. I am wondering if its the right way to ignore accented characters.

Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments