One, capitalize the first letter of the string to return a new string
1.1 Simple notation, capitalize the first letter of a wordString.prototype.firstUpperCase =function){Returnthis[0].touppercase () +This.slice (1); }1.2 Capitalize all words in a string, not first letter lowercaseString.prototype.firstUpperCase =function){ReturnThis.replace (/\b (\w) (\w*)/g,function ($0, $, $) {//\b represents delimiters Span class= "Hljs-comment" >//the first parameter, $ A, represents all substrings (all words) //the second formal parameter represents the string (first letter) that matches within the first parenthesis //the third formal parameter, the string (except for the first letter) that matches within the second parenthesis return $ 1.touppercase () + $2.tolowercase ()}); Another notation string.prototype.firstuppercase = function (return this.tolowercase (). replace (/(|^) [a-z]/g, function (u) { Return U.touppercase ()})
Second, add a flip function to the string, return a new array
String.prototype.reverse = function () {
Return Array.prototype.reverse.call (This.split (")). Join (')
String manipulation of JavaScript