function toTitleCase(str) {
  let niu = "";

  // Remove excess spaces, convert to lowercase and split words
  let words = str.replace(/\s+/g, " ").trim().toLowerCase().split(" ");
  words.forEach((word) => {
    // Convert first letter to uppercase
    niu += word.charAt(0).toUpperCase() + word.slice(1) + " ";
  });

  // Remove the space at the end
  return niu.slice(0, -1);
}
/**
 * Convert any string to Title Case.
 *
 * To convert to tileCase, there are several steps:
 * - Remove excess spaces around words (leave only one)
 * - Convert all words to lower case
 * - Capitalize the first letter of each word
 *
 * @since       1.0.0
 * @access      public
 *
 * @param {string} str  The string to convert.
 *
 * @return {string} A string in Title Case format.
 */
Convert any string to Title Case.
To convert to tileCase, there are several steps:
- Remove excess spaces around words (leave only one)
- Convert all words to lower case
- Capitalize the first letter of each word



@param {string} str  The string to convert.

@return {string} A string in Title Case format.
Convert any string to Title Case . To convert to tileCase there are several steps : - Remove excess spaces around words ( leave only one ) - Convert all words to lower case - Capitalize the first letter of each word @param { string } str The string to convert . @return { string } A string in Title Case format .
function toTitleCase(str) {
  let niu = "";
  let words = str.replace(/\s+/g, " ").trim().toLowerCase().split(" ");
  words.forEach((word) => {
    niu += word.charAt(0).toUpperCase() + word.slice(1) + " ";
  });
  return niu.slice(0, -1);
}
function toTitleCase ( str ) { let niu = "" ; let words = str . replace ( / \s+ / g , " " ) . trim ( ) . toLowerCase ( ) . split ( " " ) ; words . forEach ( ( word ) => { niu += word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) + " " ; } ) ; return niu . slice ( 0 , - 1 ) ; }
Convert any string to Title Case.
Convert any string to Title Case .
// Remove excess spaces, convert to lowercase and split words // Convert first letter to uppercase // Remove the space at the end