Here's an example:
I have this array:
const chars = [ "ä", "t", "i" ]
and I'd like to achieve this outcome:
const chars = ["a", "e", "t", "i" ]
Basically, I'd like to replace some special chars:
- ä -> a, e
- ü -> u, e
- ö -> o, e
I've been trying to use a switch function like this:
const charsArray = ["ä", "t", "i"]
const replaceChars = (char) => {
switch (char) {
case "ä":
return ("a", "e");
default:
return char;
}
};
const cleanArray = charsArray.map((c) => {return replaceChars(c)}
//output: ["e", "t", "i"] instead of: ["a","e", "t", "i"]
The problem: it only returns 1 value, so f.ex. for "ä" it only returns "e".
Any help is appreciated! Thanks!