Javascript Code Function Title Case String
Fast Simple Short Javascript Code to Title Case a string (capitalize the first letter of each word of a string)
Home
Short:
/*--------------------------------------------- fast efficient way to title case (upper case first letter of each word) of a string [str] -------------------------------------------- */ function titleCase(str) { return str.toLowerCase().split(" ") .reduce((s, c) => s + "" + (c.charAt(0).toUpperCase() + c.slice(1) + " "), "") .trim(); }
source code home