
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to capitalize the first letter of each word in a string using JavaScript?
At first, you need to split() the string on the basis of space and extract the first character using charAt(). Use toUpperCase() for the extracted character.
Example
function capitalizeTheFirstLetterOfEachWord(words) { var separateWord = words.toLowerCase().split(' '); for (var i = 0; i < separateWord.length; i++) { separateWord[i] = separateWord[i].charAt(0).toUpperCase() + separateWord[i].substring(1); } return separateWord.join(' '); } console.log(capitalizeTheFirstLetterOfEachWord("my name is john"));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo43.js.
Output
This will produce the following output with first letter capitalize −
PS C:\Users\Amit\JavaScript-code> node demo43.js My Name Is John
- Related Articles
- Python program to capitalize each word's first letter
- Capitalize last letter and Lowercase first letter of a word in Java
- Java Program to Capitalize the first character of each word in a String
- Golang program to capitalize first character of each word in a string
- Print first letter of each word in a string using C# regex
- Capitalizing first letter of each word JavaScript
- Getting first letter of each word in a String using regex in Java
- Print first letter of each word in a string in C#
- How to get first letter of each word using regular expression in Java?
- Write a Java program to capitalize each word in the string?
- Java Program to Print first letter of each word using regex
- C++ Program to Print first letter of each word using regex
- Golang program to print first letter of each word using regex
- Using a recursive function to capitalize each word in an array in JavaScript
- Return String by capitalizing first letter of each word and rest in lower case with JavaScript?

Advertisements