为什么这段代码不替换每个单词的首字母呢?

Why doesn't this piece of code replace the first letter of each word?

我试图替换每个单词的第一个字母并想出了这段代码。有谁知道为什么它不起作用?

name = 'EFEIN DOED'
name.split(' ').map(b => {
   b = b.toLowerCase();
   console.log(b);
   b[0] = 3;
   console.log(b);
   return b;
}).join(' ');

提前致谢。

除了字符串是不可变的,因此不能以这种方式编辑之外,您的总体想法是正确的。这是 returns '3fein 3oed' 的替代方案:

name.split(' ').map(b => '3' + b.toLowerCase().substring(1)).join(' ');