Answers for "how to capitalize the beginning of every word in a string javascript"

2

javascript uppercase first letter of each word

const str = 'captain picard';

function capitalize(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

const caps = str.split(' ').map(capitalize).join(' ');
caps; // 'Captain Picard'
Posted by: Guest on October-27-2020
0

capitalize first letter of each word javascript

const titleCase = function(text) {
  let newText = '';
  text = text.toLowerCase();
  text = text.charAt(0).toUpperCase() + text.slice(1);
  for (let i = 0; i < text.length; i++) {
    if (text[i] === ' ') {
      newText += ' ' + text[i+1].toUpperCase();
      i++;
    } else {
      newText += text[i];
    }
  }
  return newText;
}
Posted by: Guest on January-12-2021

Code answers related to "how to capitalize the beginning of every word in a string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language