给定一组单词,我需要将它们放在以单词的第一个字母为键的散列中。我有单词 = {},键 A..Z 和 0 表示数字和符号。我正在做类似的事情
var firstLetter = name.charAt(0);
firstLetter = firstLetter.toUpperCase();
if (firstLetter < "A" || firstLetter > "Z") {
firstLetter = "0";
}
if (words[firstLetter] === undefined) {
words[firstLetter] = [];
}
words[firstLetter].push(name);
但这会因分词和其他字符而失败,例如Ärzteversorgung一词。那个词放在“0”数组中,我怎么能把它放在“A”数组中?