0

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.

  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?

Mads Hjorth
  • 439
  • 1
  • 9
  • 23

1 Answers1

5

Update -

If you still need a method to do that, try this regex pattern

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'))
Satyam Pathak
  • 6,612
  • 3
  • 25
  • 52