将map()函数应用到变量str,以便将字符串中的每一个单词转换为大写。在javascript里。
str = "hello my name is jon and i live in. canada."发布于 2022-01-07 16:07:54
"hello my name is jon and i live in. canada."
.split(" ")
.map((word, idx) => idx % 2 === 0 ? word : word.toUpperCase())
.join(" ")诀窍是:
idx % 2 !== 0.
join返回空格时使用toUpperCase()。https://stackoverflow.com/questions/70623984
复制相似问题