{"id":5514,"date":"2025-05-29T13:29:00","date_gmt":"2025-06-04T06:15:59","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5514"},"modified":"2025-06-04T13:29:00","modified_gmt":"2025-06-04T06:15:59","slug":"%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89%e6%8f%9b%e7%82%bamap%e5%b0%8d%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%bd%bf%e7%94%a8typescriptmap%e5%b0%87%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89%e6%8f%9b%e7%82%bamap%e5%b0%8d%e8%b1%a1\/","title":{"rendered":"\u7528 TypeScript Map \u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f15\u9b06\u8f49\u63db\u70ba Map \u5c0d\u8c61\uff1a\u5f9e\u5165\u9580\u5230\u7cbe\u901a"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Map, fromQueryString, \u67e5\u8a62\u5b57\u7b26\u4e32, JavaScript \u6559\u5b78\"><\/p>\n<h1>\u7528 TypeScript Map \u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f15\u9b06\u8f49\u63db\u70ba Map \u5c0d\u8c61<\/h1>\n<p>\u5728\u7576\u4eca\u7684 web \u958b\u767c\u4e2d\uff0cTypeScript \u4f5c\u70ba JavaScript \u7684\u8d85\u96c6\uff0c\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u66f4\u5f37\u5927\u7684\u5de5\u5177\u548c\u529f\u80fd\u3002\u5176\u4e2d\uff0cTypeScript \u7684 Map \u5c0d\u8c61\u662f\u4e00\u500b\u975e\u5e38\u5be6\u7528\u7684\u6578\u64da\u7d50\u69cb\uff0c\u53ef\u4ee5\u8f15\u9b06\u5730\u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f49\u63db\u70ba Map \u5c0d\u8c61\uff0c\u9019\u5c0d\u65bc\u8655\u7406 URL \u53c3\u6578\u548c\u6578\u64da\u7ba1\u7406\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u8a73\u76e1\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 TypeScript Map \u7684 fromQueryString \u65b9\u6cd5\uff0c\u8b93\u9019\u4e00\u904e\u7a0b\u8b8a\u5f97\u7c21\u55ae\u660e\u77ad\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f TypeScript Map\uff1f<\/h2>\n<p>Map \u662f\u4e00\u7a2e\u73fe\u4ee3 JavaScript \u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u5b58\u5132\u9375\u503c\u5c0d\u3002\u5728 Map \u4e2d\uff0c\u9375\u7684\u9806\u5e8f\u662f\u6709\u4fdd\u969c\u7684\uff0c\u9019\u4f7f\u5f97\u5b83\u5728\u9700\u8981\u5feb\u901f\u67e5\u627e\u548c\u66f4\u65b0\u6578\u64da\u6642\u975e\u5e38\u9ad8\u6548\u3002\u8207\u666e\u901a\u5c0d\u8c61\u76f8\u6bd4\uff0cMap \u5c0d\u5404\u7a2e\u6578\u64da\u985e\u578b\uff08\u5982\u5b57\u7b26\u4e32\u3001\u6578\u5b57\u3001\u5c0d\u8c61\u7b49\uff09\u90fd\u80fd\u5f88\u597d\u5730\u8655\u7406\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u4ee5\u66f4\u9748\u6d3b\u7684\u65b9\u5f0f\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f49\u63db\u70ba Map \u5c0d\u8c61\uff1f<\/h2>\n<p>TypeScript Map \u63d0\u4f9b\u4e86\u4e00\u500b\u65b9\u4fbf\u7684 fromQueryString \u65b9\u6cd5\uff0c\u8a72\u65b9\u6cd5\u80fd\u5920\u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f49\u63db\u70ba Map \u5c0d\u8c61\u3002\u67e5\u8a62\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: python\">\nkey1=value1&key2=value2&key3=value3\n<\/pre>\n<p>\u5728\u9019\u7a2e\u683c\u5f0f\u4e2d\uff0c\u6bcf\u500b\u9375\u503c\u5c0d\u7531\u201c&#038;\u201d\u5206\u9694\uff0c\u800c\u6bcf\u500b\u9375\u8207\u5176\u5c0d\u61c9\u7684\u503c\u5247\u7531\u201c=\u201d\u5206\u9694\u3002<\/p>\n<p>\u8981\u4f7f\u7528 fromQueryString \u65b9\u6cd5\uff0c\u9996\u5148\u9700\u8981\u5275\u5efa\u4e00\u500b Map \u5c0d\u8c61\uff1a<\/p>\n<pre class=\"brush: python\">\nlet map = new Map();\n<\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528 fromQueryString \u65b9\u6cd5\u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f49\u63db\u70ba Map \u5c0d\u8c61\uff1a<\/p>\n<pre class=\"brush: python\">\nlet queryString = \"key1=value1&key2=value2&key3=value3\";\nmap.fromQueryString(queryString);\n<\/pre>\n<p>\u6b64\u6642\uff0cMap \u5c0d\u8c61\u4e2d\u5c07\u5305\u542b\u4ee5\u4e0b\u9375\u503c\u5c0d\uff1a<\/p>\n<pre class=\"brush: python\">\nkey1: value1\nkey2: value2\nkey3: value3\n<\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u901a\u904e Map \u5c0d\u8c61\u7684 get \u65b9\u6cd5\u4f86\u7372\u53d6\u7279\u5b9a\u9375\u7684\u503c\uff1a<\/p>\n<pre class=\"brush: python\">\nlet value = map.get(\"key1\");\nconsole.log(value); \/\/ value1\n<\/pre>\n<p>\u6b64\u5916\uff0c\u9084\u53ef\u4ee5\u4f7f\u7528 set \u65b9\u6cd5\u4f86\u66f4\u65b0\u67d0\u500b\u9375\u7684\u503c\uff1a<\/p>\n<pre class=\"brush: python\">\nmap.set(\"key1\", \"newValue\");\nlet newValue = map.get(\"key1\");\nconsole.log(newValue); \/\/ newValue\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u8a73\u7d30\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 TypeScript Map \u5c07\u67e5\u8a62\u5b57\u7b26\u4e32\u8f49\u63db\u70ba Map \u5c0d\u8c61\u3002Map \u4f5c\u70ba\u4e00\u7a2e\u73fe\u4ee3\u7684 JavaScript \u6578\u64da\u7d50\u69cb\uff0c\u4e0d\u50c5\u80fd\u6709\u6548\u5730\u5b58\u5132\u9375\u503c\u5c0d\uff0c\u9084\u80fd\u5feb\u901f\u67e5\u627e\u548c\u66f4\u65b0\u6578\u64da\u3002\u638c\u63e1 fromQueryString \u65b9\u6cd5\u5f8c\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u52a0\u9ad8\u6548\u5730\u8655\u7406 URL \u53c3\u6578\u53ca\u5176\u4ed6\u6578\u64da\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\u548c\u4ee3\u78bc\u8cea\u91cf\u3002<\/p>\n<h2>\u66f4\u591a\u4f7f\u7528\u6280\u5de7<\/h2>\n<p>\u9664\u4e86 fromQueryString \u65b9\u6cd5\u5916\uff0cTypeScript Map \u9084\u63d0\u4f9b\u4e86\u5176\u4ed6\u6709\u7528\u7684\u65b9\u6cd5\uff0c\u5982 has\u3001delete\u3001clear \u548c size \u7b49\uff0c\u9019\u4e9b\u90fd\u53ef\u4ee5\u5e6b\u52a9\u60a8\u66f4\u597d\u5730\u7ba1\u7406\u548c\u64cd\u4f5c Map \u5c0d\u8c61\u3002\u6b64\u5916\uff0cMap \u7684 forEach \u65b9\u6cd5\u4f7f\u5f97\u5c0d\u6bcf\u500b\u9375\u503c\u5c0d\u9032\u884c\u8fed\u4ee3\u64cd\u4f5c\u8b8a\u5f97\u8f15\u800c\u6613\u8209\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u4e86\u6578\u64da\u8655\u7406\u7684\u9748\u6d3b\u6027\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528TypeScriptMap\u5c07\u6307\u5b9a\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u8f49\u63db\u70baMap\u5c0d\u8c61\uff0c\u4e26\u63d0\u4f9b\u7c21\u55ae\u7684\u793a\u4f8b\u4f86\u89e3\u91cb\u5982\u4f55\u4f7f\u7528\u5b83\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-5514","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-1qW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5514","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=5514"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5514\/revisions"}],"predecessor-version":[{"id":5515,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5514\/revisions\/5515"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}