Write a function to capitalize the first letter of each word in a sentence using node js

// Function to capitalize the first letter of each word in a sentence
function capitalizeWords(sentence) {
  return sentence.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
}

// Example usage
const originalSentence = "hello world";
const capitalizedSentence = capitalizeWords(originalSentence);
console.log(capitalizedSentence);

 

Post your Answer