Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

แปลง String เป็น Uppercase ด้วย JavaScript

เรียนรู้วิธีแปลงข้อความทุก case เป็นตัวพิมพ์ใหญ่ (uppercase) ด้วย JavaScript

ใช้เมธอด toUpperCase():

let someText = "Here is some text. Let us convert it all to uppercase";
someText.toUpperCase();
console.log(someText.toUpperCase());
// "HERE IS SOME TEXT. LET US CONVERT IT ALL TO UPPERCASE"

toUpperCase() คืนค่า string ใหม่ ไม่ mutate string ต้นฉบับ