Determining the case (upper/lower) of the first letter in a string
问题 In a web application, how do I determine whether the first letter in a given string is upper- or lower-case using JavaScript? 回答1: You can use toUpperCase : if(yourString.charAt(0) === yourString.charAt(0).toUpperCase()) { //Uppercase! } If you're going to be using this on a regular basis, I would suggest putting it in a function on the String prototype, something like this: String.prototype.isFirstCapital = function() { return this.charAt(0) === this.charAt(0).toUpperCase(); } if(yourString