{"id":5589,"date":"2023-01-06T09:50:46","date_gmt":"2023-01-06T01:50:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5589"},"modified":"2023-01-06T09:50:46","modified_gmt":"2023-01-06T01:50:46","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8react-js%e5%b0%87%e5%ad%97%e4%b8%b2%e7%9a%84%e9%a6%96%e5%ad%97%e6%af%8d%e5%a4%a7%e5%af%ab","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8react-js%e5%b0%87%e5%ad%97%e4%b8%b2%e7%9a%84%e9%a6%96%e5%ad%97%e6%af%8d%e5%a4%a7%e5%af%ab\/","title":{"rendered":"\u5982\u4f55\u5229\u7528React.JS\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.JS, capitalizeFirstLetter\"><\/p>\n<h1>\u4f7f\u7528 React.JS \u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb(capitalizeFirstLetter)<\/h1>\n<p>React.JS \u662f\u4e00\u500b\u7531 Facebook \u6240\u958b\u767c\u7684 JavaScript \u51fd\u5f0f\u5eab\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5efa\u7acb\u4e92\u52d5\u5f0f\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 React.JS \u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4f86\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\uff0c\u4e5f\u5c31\u662f\u6240\u8b02\u7684 capitalizeFirstLetter\u3002<\/p>\n<p>\u5728 React.JS \u4e2d\uff0c\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\u7684\u65b9\u6cd5\u5f88\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u4f7f\u7528 JavaScript \u7684 <code>toUpperCase()<\/code> \u65b9\u6cd5\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u5c07\u5b57\u4e32 <code>hello world<\/code> \u7684\u9996\u5b57\u6bcd\u5927\u5beb\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet str = \"hello world\";\nlet result = str.charAt(0).toUpperCase() + str.slice(1);\nconsole.log(result); \/\/ Hello world\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 <code>charAt()<\/code> \u65b9\u6cd5\u4f86\u53d6\u5f97\u5b57\u4e32\u7684\u7b2c\u4e00\u500b\u5b57\u5143\uff0c\u7136\u5f8c\u4f7f\u7528 <code>toUpperCase()<\/code> \u65b9\u6cd5\u5c07\u5176\u8f49\u63db\u70ba\u5927\u5beb\uff0c\u6700\u5f8c\u4f7f\u7528 <code>slice()<\/code> \u65b9\u6cd5\u5c07\u5b57\u4e32\u4e2d\u9664\u4e86\u7b2c\u4e00\u500b\u5b57\u5143\u4ee5\u5916\u7684\u90e8\u5206\u62fc\u63a5\u8d77\u4f86\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\u7684\u7d50\u679c\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u9664\u4e86\u4e0a\u9762\u63d0\u5230\u7684\u65b9\u6cd5\u4e4b\u5916\uff0c\u9084\u53ef\u4ee5\u4f7f\u7528 JavaScript \u7684 <code>replace()<\/code> \u65b9\u6cd5\u4f86\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre class=\"brush: javascript\">\nlet str = \"hello world\";\nlet result = str.replace(\/^\\w\/, c => c.toUpperCase());\nconsole.log(result); \/\/ Hello world\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86\u6b63\u5247\u8868\u9054\u5f0f <code>\/^\\w\/<\/code> \u4f86\u53d6\u5f97\u5b57\u4e32\u7684\u7b2c\u4e00\u500b\u5b57\u5143\uff0c\u7136\u5f8c\u4f7f\u7528 <code>replace()<\/code> \u65b9\u6cd5\u5c07\u5176\u8f49\u63db\u70ba\u5927\u5beb\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\u7684\u7d50\u679c\u3002<\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0c\u5728 React.JS \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 JavaScript \u7684 <code>toUpperCase()<\/code> \u6216 <code>replace()<\/code> \u65b9\u6cd5\u4f86\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\uff0c\u4ee5\u6eff\u8db3\u958b\u767c\u8005\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528React.JS\u4f86\u5c07\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u5927\u5beb\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528capitalizeFirstLetter()\u51fd\u6578\u4f86\u5be6\u73fe\u6b64\u529f\u80fd\uff0c\u4e26\u63d0\u4f9b\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\u4ee5\u53ca\u8a73\u7d30\u7684\u89e3\u8aaa\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[184,183],"tags":[182,181],"class_list":["post-5589","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1s9","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5589"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5589\/revisions"}],"predecessor-version":[{"id":5590,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5589\/revisions\/5590"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}