{"id":5246,"date":"2023-01-05T12:17:09","date_gmt":"2023-01-05T04:17:09","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5246"},"modified":"2023-01-05T12:17:09","modified_gmt":"2023-01-05T04:17:09","slug":"%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescriptmap%e5%bb%ba%e7%ab%8b%e6%96%b0%e7%9a%84map%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescriptmap%e5%bb%ba%e7%ab%8b%e6%96%b0%e7%9a%84map%e5%af%b9%e8%b1%a1\/","title":{"rendered":"\u4e86\u89e3\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5efa\u7acb\u65b0\u7684Map\u5bf9\u8c61"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, new Map()\"><\/p>\n<h1>\u4f7f\u7528 TypeScript Map \u5efa\u7acb\u65b0\u7684 Map \u5bf9\u8c61(new Map())<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u958b\u767c\u51fa\u5065\u58ef\u7684\u7a0b\u5f0f\u78bc\u3002TypeScript \u63d0\u4f9b\u4e86\u4e00\u7a2e Map \u985e\u578b\uff0c\u53ef\u4ee5\u7528\u4f86\u5efa\u7acb\u65b0\u7684 Map \u5c0d\u8c61\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f Map \u5c0d\u8c61\uff1f<\/h2>\n<p>Map \u5c0d\u8c61\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5b58\u5132\u9375\u503c\u5c0d\uff0c\u5176\u4e2d\u9375\u53ef\u4ee5\u662f\u4efb\u4f55\u7a2e\u985e\u7684\u503c\uff0c\u800c\u503c\u53ef\u4ee5\u662f\u4efb\u4f55\u7a2e\u985e\u7684\u503c\u3002Map \u5c0d\u8c61\u53ef\u4ee5\u7528\u4f86\u5b58\u5132\u4efb\u4f55\u985e\u578b\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u7269\u4ef6\u7b49\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5efa\u7acb\u65b0\u7684 Map \u5c0d\u8c61\uff1f<\/h2>\n<p>\u4f7f\u7528 TypeScript Map \u5efa\u7acb\u65b0\u7684 Map \u5c0d\u8c61\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u4f7f\u7528 new Map() \u65b9\u6cd5\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u5c07\u5efa\u7acb\u4e00\u500b\u65b0\u7684 Map \u5c0d\u8c61\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet myMap = new Map();\n<\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u53ef\u4ee5\u4f7f\u7528 set() \u65b9\u6cd5\u5c07\u9375\u503c\u5c0d\u6dfb\u52a0\u5230 Map \u5c0d\u8c61\u4e2d\uff1a<\/p>\n<pre class=\"brush: typescript\">\nmyMap.set('name', 'John');\nmyMap.set('age', 30);\n<\/pre>\n<p>\u6700\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 get() \u65b9\u6cd5\u7372\u53d6 Map \u5c0d\u8c61\u4e2d\u7684\u503c\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet name = myMap.get('name'); \/\/ John\nlet age = myMap.get('age'); \/\/ 30\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528 TypeScript Map \u5efa\u7acb\u65b0\u7684 Map \u5c0d\u8c61\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u4f7f\u7528 new Map() \u65b9\u6cd5\uff0c\u7136\u5f8c\u4f7f\u7528 set() \u548c get() \u65b9\u6cd5\u5c31\u53ef\u4ee5\u5c0d Map \u5c0d\u8c61\u9032\u884c\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5efa\u7acb\u65b0\u7684Map\u5bf9\u8c61\uff0cMap\u662f\u4e00\u79cd\u952e\u503c\u5bf9\u7684\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u548c\u68c0\u7d22\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5efa\u7acb\u65b0\u7684Map\u5bf9\u8c61\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u6765\u5b58\u50a8\u548c\u68c0\u7d22\u6570\u636e\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":[187],"tags":[186],"class_list":["post-5246","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1mC","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5246","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=5246"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5246\/revisions"}],"predecessor-version":[{"id":5247,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5246\/revisions\/5247"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}