
- 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
Title Case A Sentence JavaScript
Let’s say we are required to write a function that accepts a string and capitalizes the first letter of every word in that string and changes the case of all the remaining letters to lowercase.
For example, if the input string is −
hello world coding is very interesting
The output should be −
Hello World Coding Is Very Interesting
Let’s define a function capitaliseTitle() that takes in a string and capitalises the first letter of each word and returns the string −
Example
let str = 'hello world coding is very interesting'; const capitaliseTitle = (str) => { const string = str .toLowerCase() .split(" ") .map(word => { return word[0] .toUpperCase() + word.substr(1, word.length); }) .join(" "); return string; } console.log(capitaliseTitle(str));
Output
The console output will be −
Hello World Coding Is Very Interesting
- Related Articles
- How to Title Case a sentence in JavaScript?
- Sentence Case of a given Camel cased String
- What is String Title case in C#?
- How to convert a string into Title Case in Golang?
- How to convert a string vector into title case in R?
- How to convert string to title case in C#?
- How to convert a slice of bytes in title case in Golang?
- How to edit a JavaScript alert box title?
- How to Convert Lowercase to Proper or Sentence Case in Excel?
- Counting number of words in a sentence in JavaScript
- Arranging words by their length in a sentence in JavaScript
- Finding n most frequent words from a sentence in JavaScript
- Reverse all the words of sentence JavaScript
- How to display the title of a document with JavaScript?
- Is JavaScript a case sensitive language?

Advertisements