Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
378 views
in Technique[技术] by (71.8m points)

javascript - 每个单词的首字母大写[重复](Capitalize first letter in each word [duplicate])

This question already has an answer here:(这个问题已经在这里有了答案:)

Convert string to title case with JavaScript 52 answers(使用JavaScript 52将答案 转换为标题大小写的字符串)

I am trying to capitalize the first letter in each word for my page title in Nuxt.js My current code capitalizes the first word, however I need it to also capitalize the rest.(我试图在Nuxt.js中页面标题的每个单词的首字母大写。)

head() { return { title: this.$route.params.models.charAt(0).toUpperCase() + this.$route.params.models.slice(1).split('-').join(' ') + ' | ' + this.title, meta: [ { hid: 'description', name: 'description', content: '' } ] } } How would I approach this?(我将如何处理?)   ask by Mads Hjorth translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Update -(更新-)

If you still need a method to do that, try this regex pattern(如果您仍需要执行此操作的方法,请尝试以下regex模式) function capitalize(value){ return value.replace(/(?:^|\s|-)\S/g, x => x.toUpperCase()); } console.log(capitalize('hello i misunderstood your requirement initially by skipping the whole description'))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...