function toTitleCase(str) { //store the first letter in firstChar let firstChar = str[0] || ""; //capitalize firstChar firstChar = firstChar.toUpperCase(); //store the remaining characters in a variable otherChars let otherChars = ""; if (str.length > 1) otherChars = str.substring(1, str.length); return `${firstChar}${otherChars}`; //return a concatenation of firstChar and otherChars }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter