This article mainly describes how to capitalize the first letter of each word in a string, and you need a friend to refer to the
In a string, each word is separated by a space and the number of spaces is not limited to the following code: function capitalize (Sting) {var words = String.Split (""); for (var i = 0; i < words.length i++) {Words[i] = Words[i].charat (0). toUpperCase () + words[i].slice (1); Return Words.join (""); The var string = "Ajax Cookie Event object"; Capitalize (string); "Ajax Cookie Event Object" notices the key code in the code as follows: Words[i] = Words[i].charat (0). toUpperCase () + words[i].slice (1); Words[i].charat (0). toUpperCase () simply takes the first letter of the string and converts it to uppercase, and it does not change the original string, so you need to connect to the other characters in the original string and assign the new value to the original string