将字符串首字母大写。
使用解构和 toUpperCase()
大写第一个字母,用 ...rest
获得第一个字母后字符数组,然后 Array.join('')
再次使它成为一个字符串。 省略 lowerRest
参数以保持字符串的剩余部分不变,或者将其设置为 true
这将会使字符串的剩余部分都转换为小写。
const capitalize = ([first, ...rest], lowerRest = false) => first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join(''));
capitalize('fooBar'); // 'FooBar' capitalize('fooBar', true); // 'Foobar'
最新评论
写的挺好的
有没有兴趣翻译 impatient js? https://exploringjs.com/impatient-js/index.html
Flexbox playground is so great!
感谢总结。
awesome!
这个好像很早就看到类似的文章了
比其他的教程好太多了
柯理化讲的好模糊…没懂