{"id":5548,"date":"2025-05-28T13:50:14","date_gmt":"2025-06-04T06:16:13","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5548"},"modified":"2025-06-04T13:50:14","modified_gmt":"2025-06-04T06:16:13","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescriptmap%e8%8e%b7%e5%8f%96map%e5%af%b9%e8%b1%a1%e7%9a%84%e6%89%80%e6%9c%89%e5%85%83%e7%b4%a0","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8typescriptmap%e8%8e%b7%e5%8f%96map%e5%af%b9%e8%b1%a1%e7%9a%84%e6%89%80%e6%9c%89%e5%85%83%e7%b4%a0\/","title":{"rendered":"\u6df1\u5165\u4e86\u89e3 TypeScript \u7684 Map\uff1a\u8f15\u9b06\u7372\u53d6\u6240\u6709\u5143\u7d20"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, getEntries, TypeScript \u6559\u5b78, JavaScript, \u9375\u503c\u5c0d, \u958b\u767c\u8005\u5de5\u5177\"><\/p>\n<h1>\u6df1\u5165\u4e86\u89e3 TypeScript \u7684 Map\uff1a\u8f15\u9b06\u7372\u53d6\u6240\u6709\u5143\u7d20<\/h1>\n<p>TypeScript \u662f JavaScript \u7684\u5f37\u5927\u8d85\u96c6\uff0c\u63d0\u4f9b\u4e86\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\u7b49\u591a\u9805\u9ad8\u7d1a\u529f\u80fd\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u64b0\u5beb\u51fa\u66f4\u52a0\u5065\u58ef\u7684\u4ee3\u78bc\u3002\u4f5c\u70ba\u4e00\u500b\u9748\u6d3b\u4e14\u9ad8\u6548\u7684\u6578\u64da\u7d50\u69cb\uff0cTypeScript \u7684 Map \u7528\u65bc\u5b58\u5132\u9375\u503c\u5c0d\uff0c\u4f7f\u6578\u64da\u7684\u64cd\u4f5c\u8b8a\u5f97\u66f4\u52a0\u4fbf\u6377\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 TypeScript \u7684 Map \u4f86\u8f15\u9b06\u7372\u53d6 Map \u5c0d\u8c61\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 TypeScript Map \u7372\u53d6\u6240\u6709\u5143\u7d20<\/h2>\n<p>TypeScript \u4e2d\u7684 Map \u63d0\u4f9b\u4e86\u591a\u7a2e\u65b9\u6cd5\u4f86\u64cd\u4f5c\u9375\u503c\u5c0d\uff0c\u5176\u4e2d\u4e00\u500b\u5e38\u7528\u7684\u65b9\u6cd5\u662f <span style=\"font-weight: bold;\">entries()<\/span>\uff0c\u9019\u500b\u65b9\u6cd5\u8fd4\u56de\u4e00\u500b\u53ef\u8fed\u4ee3\u7684\u5c0d\u8c61\uff0c\u5305\u542b Map \u4e2d\u7684\u6240\u6709\u9375\u503c\u5c0d\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 TypeScript Map \u7372\u53d6\u6240\u6709\u5143\u7d20\u7684\u793a\u4f8b\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet map = new Map();\nmap.set('name', 'John');\nmap.set('age', 30);\n\n\/\/ \u4f7f\u7528 entries() \u65b9\u6cd5\u7372\u53d6\u6240\u6709\u5143\u7d20\nlet entries = map.entries();\n\nfor (let entry of entries) {\n    console.log(`<span class=\"katex math inline\">{entry[0]}:<\/span>{entry[1]}`);\n}\n<\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b Map \u5c0d\u8c61\uff0c\u7136\u5f8c\u4f7f\u7528 <span style=\"font-weight: bold;\">entries()<\/span> \u65b9\u6cd5\u4f86\u7372\u53d6\u6240\u6709\u5143\u7d20\u3002\u63a5\u8457\uff0c\u6211\u5011\u901a\u904e <span style=\"font-weight: bold;\">for&#8230;of<\/span> \u5faa\u74b0\u904d\u6b77\u6bcf\u4e00\u500b\u9375\u503c\u5c0d\uff0c\u4e26\u5c07\u5b83\u5011\u6253\u5370\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<p>\u8f38\u51fa\u7d50\u679c\u5c07\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre class=\"brush: python\">\nname: John\nage: 30\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5b78\u6703\u4e86\u5982\u4f55\u4f7f\u7528 TypeScript \u7684 Map \u4f86\u7372\u53d6\u6240\u6709\u5143\u7d20\u3002\u6211\u5011\u5229\u7528\u4e86 <span style=\"font-weight: bold;\">entries()<\/span> \u65b9\u6cd5\u4f86\u65b9\u4fbf\u5730\u7372\u53d6 Map \u7684\u6240\u6709\u9375\u503c\u5c0d\uff0c\u4e26\u4f7f\u7528 <span style=\"font-weight: bold;\">for&#8230;of<\/span> \u5faa\u74b0\u9032\u884c\u904d\u6b77\u8207\u8f38\u51fa\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u9032\u4e00\u6b65\u4e86\u89e3 TypeScript \u7684 Map \u4ee5\u53ca\u5176\u4ed6\u65b9\u6cd5\uff0c\u5efa\u8b70\u67e5\u770b\u5b98\u65b9\u6587\u6a94\uff0c\u9019\u5c07\u70ba\u4f60\u7684\u958b\u767c\u5de5\u4f5c\u63d0\u4f9b\u66f4\u591a\u7684\u5e6b\u52a9\u8207\u6307\u5f15\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528TypeScriptMap\u7684getEntries\u51fd\u6578\u4f86\u83b7\u53d6Map\u5c0d\u8c61\u7684\u6240\u6709\u5143\u7d20\uff0c\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Map\u5c0d\u8c61\u7684getEntries\u51fd\u6578\u4f86\u7372\u53d6Map\u5c0d\u8c61\u7684\u6240\u6709\u5143\u7d20\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u63d0\u9ad8\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\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":[187],"tags":[186],"class_list":["post-5548","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-1ru","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5548","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=5548"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5548\/revisions"}],"predecessor-version":[{"id":5549,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5548\/revisions\/5549"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}