{"id":5608,"date":"2023-01-06T10:01:54","date_gmt":"2023-01-06T02:01:54","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5608"},"modified":"2023-01-06T10:01:54","modified_gmt":"2023-01-06T02:01:54","slug":"%e4%ba%86%e8%a7%a3react-js%e4%b8%ad%e7%9a%84iscapitalized%e5%87%bd%e6%95%b8%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%ba%86%e8%a7%a3react-js%e4%b8%ad%e7%9a%84iscapitalized%e5%87%bd%e6%95%b8%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u4e86\u89e3React.JS\u4e2d\u7684isCapitalized\u51fd\u6578\u529f\u80fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React.JS, isCapitalized\"><\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 React.JS \u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff08isCapitalized\uff09<\/h1>\n<p>React.JS \u662f\u4e00\u500b\u7528\u65bc\u69cb\u5efa\u7528\u6236\u754c\u9762\u7684 JavaScript \u51fd\u5f0f\u5eab\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u8f15\u9b06\u5730\u69cb\u5efa\u9ad8\u6027\u80fd\u7684\u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff08isCapitalized\uff09\u3002<\/p>\n<h2>\u4f7f\u7528 React.JS \u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff08isCapitalized\uff09<\/h2>\n<p>\u8981\u4f7f\u7528 React.JS \u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff08isCapitalized\uff09\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4e2d\u7684 <code>String.prototype.charAt()<\/code> \u65b9\u6cd5\u3002\u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u8fd4\u56de\u6307\u5b9a\u4f4d\u7f6e\u7684\u5b57\u7b26\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5b83\u4f86\u6aa2\u67e5\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u500b\u5b57\u7b26\u662f\u5426\u70ba\u5927\u5beb\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 <code>String.prototype.charAt()<\/code> \u65b9\u6cd5\u4f86\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction isCapitalized(str) {\n  const firstChar = str.charAt(0);\n  return firstChar === firstChar.toUpperCase();\n}\n\nconsole.log(isCapitalized('React')); \/\/ true\nconsole.log(isCapitalized('react')); \/\/ false\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>String.prototype.charAt()<\/code> \u65b9\u6cd5\u4f86\u6aa2\u67e5\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u500b\u5b57\u7b26\uff0c\u7136\u5f8c\u4f7f\u7528 <code>String.prototype.toUpperCase()<\/code> \u65b9\u6cd5\u5c07\u5176\u8f49\u63db\u70ba\u5927\u5beb\uff0c\u6700\u5f8c\u6bd4\u8f03\u5169\u500b\u5b57\u7b26\u662f\u5426\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u6b64\u5916\uff0c\u6211\u5011\u9084\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4e2d\u7684 <code>String.prototype.match()<\/code> \u65b9\u6cd5\u4f86\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\u3002\u9019\u500b\u65b9\u6cd5\u53ef\u4ee5\u6aa2\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5b83\u4f86\u6aa2\u67e5\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u500b\u5b57\u7b26\u662f\u5426\u70ba\u5927\u5beb\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 <code>String.prototype.match()<\/code> \u65b9\u6cd5\u4f86\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff1a<\/p>\n<pre class=\"brush: javascript\">\nfunction isCapitalized(str) {\n  return str.match(\/^[A-Z]\/);\n}\n\nconsole.log(isCapitalized('React')); \/\/ true\nconsole.log(isCapitalized('react')); \/\/ false\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>String.prototype.match()<\/code> \u65b9\u6cd5\u4f86\u6aa2\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7b26\u5408\u6307\u5b9a\u7684\u6b63\u5247\u8868\u9054\u5f0f\uff0c\u5982\u679c\u7b26\u5408\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 React.JS \u4f86\u5224\u65b7\u5b57\u4e32\u662f\u5426\u70ba\u9996\u5b57\u6bcd\u5927\u5beb\uff08isCapitalized\uff09\u3002\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 JavaScript \u4e2d\u7684 <code>String.prototype.charAt()<\/code> \u65b9\u6cd5\u6216 <code>String.prototype.match()<\/code> \u65b9\u6cd5\u4f86\u5be6\u73fe\u9019\u500b\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39React.JS\u4e2d\u7684isCapitalized\u51fd\u6578\uff0c\u5b83\u53ef\u4ee5\u6aa2\u67e5\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u662f\u5426\u5927\u5beb\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u7c21\u55ae\u7684\u7bc4\u4f8b\u4f86\u89e3\u91cb\u5b83\u7684\u529f\u80fd\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-5608","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-1ss","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5608","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=5608"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5608\/revisions"}],"predecessor-version":[{"id":5609,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5608\/revisions\/5609"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}