In Javascript how to make the first letter of a string uppercase / capitalize

Example scenarios are:

  • capitalize => Capitalize
  • capitalize me => Capitalize me

 

The code :

const capitalize = string =>
  string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();