Javascript - Đổi chữ hoa mỗi từ thành chữ thường

Viết hàm JS để đổi chữ hoa mỗi từ thành chữ thường

Ví dụ:

JavaScript: Uncapitalize the first letter of each word of a string

Mã nguồn:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JavaScript program to convert the letters of a given string  in alphabetical order.</title>
</head>
<script>
	function unCapitalize_Words(str)
	{ 
	  return str.replace(/\w\S*/g, 
		function(txt)
		   {
			  return txt.charAt(0).toLowerCase() + txt.substr(1).toLowerCase();});
	}

	document.write(unCapitalize_Words('Js String Exercises'));
</script>
<body>

</body>
</html> 

Xem ví dụ

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

Flowchart: JavaScript: Uncapitalize  the first character of 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").