JavaScript program that capitalizes the first letter of each word in a string
Posted by SceDev
Last Updated: February 24, 2024

Write a JavaScript program that capitalizes the first letter of each word in a string.

 

Code:

function capitalizeLetters(inputstring) {
    return inputstring.split(' ').map(x => x.charAt(0).toUpperCase() + x.slice(1)).join(' ');
  }


var result = capitalizeLetters('hello world');

console.log(result);