Javascript - Tạo chữ cái đầu tiên của mỗi từ là chữ hoa

Tạo chữ cái đầu tiên của mỗi từ là chữ hoa trong một chuỗi

Ví dụ:

JavaScript: Make capitalize the first letter of each word in a string

Mã nguồn:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Make capitalize the first letter of each word in a string</title>
 <script>
//capitalize_Words 
function capitalize_Words(str)
{
 return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
document.write(capitalize_Words('js string exercises'));
</script>
</head>
<body>
</body>
</html>

Lưu đồ thuật toán:

Flowchart: JavaScript- Make capitalize the first letter of each word in a string


Chatbot Tư vấn Lộ trình CNTT 🤖
Chào bạn! Tôi có thể tư vấn về các lộ trình học CNTT dựa trên roadmap.w3typing.com. Hãy chọn một từ khóa dưới đây hoặc gõ câu hỏi của bạn (ví dụ: "Frontend", "Backend", "Python", "DevOps").