Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Better ways to modify string with multiple methods using JavaScript
To modify string, you can use toLowerCase() as well as toUpperCase(). Let’s say the following is our string −
var sentence = "tHIS iS tHE JavaScript pROGRAM";
To modify and display in proper case, the code is as follows −
Example
var sentence = "tHIS iS tHE JavaScript pROGRAM";
function modifyStringWithMultipleMethods(sentence) {
return sentence.charAt(0).toUpperCase() +
sentence.slice(1).toLowerCase();
}
console.log(modifyStringWithMultipleMethods(sentence));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo51.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo51.js This is the JavaScript program
Advertisements
