Created
June 20, 2020 06:21
-
-
Save ashishlahoti/6082f3becae9b59ec00f499a04830d62 to your computer and use it in GitHub Desktop.
How to Capitalize First Letter of String in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// es5 way | |
function capitalize(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
// es6 way using destructuring | |
const capitalize = ([first,...rest]) => first.toUpperCase() + rest.join(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment