
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return String By Capitalizing First Letter Of Each Word And Rest In Lower Case With JavaScript
For this, use toUpperCase() along with toLowerCase(). Following is the code −
Example
function capitalEveryFirstletter(subjectTitle) { return subjectTitle.split(' ') .map(st => st.charAt(0).toUpperCase() + st.slice(1).toLowerCase()) .join(' ');; } var subjectTitle="iNtroduction tO JavaScript ProgRAMMINg"; var output=capitalEveryFirstletter(subjectTitle); console.log("The result="+output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo74.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo74.js The result=Introduction To JavaScript Programming
Advertisements