Để sửa đổi chuỗi, dùng toLowerCase() và toUpperCase(). Giả sử chuỗi:
var sentence = "tHIS iS tHE JavaScript pROGRAM";
Mã sửa đổi hiển thị đúng kiểu:
Ví dụ
var sentence = "tHIS iS tHE JavaScript pROGRAM"; function modifyStringWithMultipleMethods(sentence) { return sentence.charAt(0).toUpperCase() + sentence.slice(1).toLowerCase(); } console.log(modifyStringWithMultipleMethods(sentence));Chạy: node fileName.js. File demo51.js.
Kết quả
PS C:\Users\Amit\JavaScript-code> node demo51.js This is the JavaScript program