javascript capitalize first letter of each word

Today, We want to share with you javascript capitalize first letter of each word.In this post we will show you javascript capitalize first letter of each word in array, hear for javascript capitalize first letters of each word in a sentence we will give you demo and example for implement.In this post, we will learn about jquery capitalize first letters with an example.

How to capitalize the first letter of each word in a string using JavaScript?

There are the Following The simple About regex capitalize first letters javascript Full Information With Example and source code.

As I will cover this Post with live Working example to develop lodash capitalize first letters, so the JavaScript: Capitalizes the first letters of each word of a given string is used for this example is following below.

Also Read This πŸ‘‰   delete button javascript - How to add and remove names on button click with JavaScript?

using toUpperCase():

Syntax

customStr.toUpperCase()

using slice():

Syntax

customStr.slice(start, end)

using charAt():

Syntax

customStr.charAt(index)

using replace():

Syntax

customStr.replace(A, B)

Example 1: uses slice() method

index.html

<!DOCTYPE html> 
<html> 
	<head> 
		<title>How to uppercase the first letter of a string in JavaScript</title> 
	</head> 
		
	<body style = "text-align:center;"> 
	
		<h1 style = "color:red;" > 
			WelcomeToPakainfo 
		</h1> 
		
		<input id = "input" type="text" name="input"/> 
		<button onclick="capitalizeFLetter()"> 
			Click to capitalize 
		</button> 
		<h3 id = "div" style="color: red"> 
		</h3> 
			
		<script> 
		
		function capitalizeFLetter() { 
		var input = document.getElementById("input"); 
		var x = document.getElementById("div"); 
		var customStr = input.value; 
		x.innerHTML = customStr[0].toUpperCase() + 
			customStr.slice(1); 
		} 
		</script> 
	</body> 
</html> 

Example 2: uses slice() method

index.html

<!DOCTYPE html> 
<html> 
	<head> 
		<title>How to Capitalize the First Letter of a String in JavaScript</title> 
	</head> 
		
	<body style = "text-align:center;"> 
	
		<h1 style = "color:red;" > 
			WelcomeToPakainfo 
		</h1> 
			
		<input id = "input" type="text" name="input"/> 
		<button onclick="capitalizeFLetter()"> 
			here Click to capitalize 
		</button> 
		<h3 id = "div" style="color: red"> 
		</h3> 
			
		<script> 
		
		function capitalizeFLetter() { 
		var input = document.getElementById("input"); 
		var x = document.getElementById("div"); 
		var customStr = input.value; 
		x.innerHTML = customStr.charAt(0).toUpperCase() + 
		customStr.slice(1); 
		} 
		</script> 
	</body> 
</html> 

Example 3: uses string.replace() method

index.html

<!DOCTYPE html> 
<html> 
	<head> 
		<title>How to make first letter of a string uppercase in JavaScript ?</title>	 
	</head> 
		
	<body style = "text-align:center;"> 
	
		<h1 style = "color:red;" > 
			WelcomeToPakainfo 
		</h1>	 
		<input id = "input" type="text" name="input"/> 
		<button onclick="capitalizeFLetter()"> 
			Click to capitalize 
		</button> 
		<h3 id = "div" style="color: red"> 
		</h3> 
			
		<script> 
		
		function capitalizeFLetter() { 
		var input = document.getElementById("input"); 
		var x = document.getElementById("div"); 
		var customStr = input.value; 
		x.innerHTML = 
		customStr.replace(/^./, customStr[0].toUpperCase()); 
		} 
		</script> 
	</body> 
</html> 

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Also Read This πŸ‘‰   Ajax Upload Multiple Images without form submit

I hope you get an idea about javascript capitalize first letter of each word.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.