{"id":5448,"date":"2023-01-05T12:41:30","date_gmt":"2023-01-05T04:41:30","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5448"},"modified":"2023-01-05T12:41:30","modified_gmt":"2023-01-05T04:41:30","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84sets%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84sets%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u7684Sets\u529f\u80fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Sets\"><\/p>\n<h1>\u4f7f\u7528 TypeScript \u4f86\u64cd\u4f5c Sets<\/h1>\n<p>Sets \u662f\u4e00\u7a2e\u8cc7\u6599\u7d50\u69cb\uff0c\u5b83\u53ef\u4ee5\u5132\u5b58\u4e00\u7d44\u4e0d\u91cd\u8907\u7684\u503c\u3002\u5728 TypeScript \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 Set \u985e\u5225\u4f86\u64cd\u4f5c Sets\u3002<\/p>\n<p><!--more--><\/p>\n<p>Set \u985e\u5225\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u65b9\u6cd5\uff0c\u8b93\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u64cd\u4f5c Sets\u3002\u4f8b\u5982\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">add()<\/span> \u65b9\u6cd5\u4f86\u65b0\u589e\u4e00\u500b\u5143\u7d20\u5230 Set \u4e2d\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet mySet = new Set();\nmySet.add(1);\nmySet.add(2);\nmySet.add(3);\n\nconsole.log(mySet); \/\/ Set { 1, 2, 3 }\n<\/pre>\n<p>\u6211\u5011\u4e5f\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">has()<\/span> \u65b9\u6cd5\u4f86\u6aa2\u67e5 Set \u4e2d\u662f\u5426\u6709\u67d0\u500b\u5143\u7d20\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet mySet = new Set();\nmySet.add(1);\nmySet.add(2);\nmySet.add(3);\n\nconsole.log(mySet.has(2)); \/\/ true\nconsole.log(mySet.has(4)); \/\/ false\n<\/pre>\n<p>\u6b64\u5916\uff0c\u6211\u5011\u9084\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">delete()<\/span> \u65b9\u6cd5\u4f86\u522a\u9664 Set \u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet mySet = new Set();\nmySet.add(1);\nmySet.add(2);\nmySet.add(3);\n\nmySet.delete(2);\n\nconsole.log(mySet); \/\/ Set { 1, 3 }\n<\/pre>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">clear()<\/span> \u65b9\u6cd5\u4f86\u6e05\u7a7a Set \u4e2d\u7684\u6240\u6709\u5143\u7d20\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet mySet = new Set();\nmySet.add(1);\nmySet.add(2);\nmySet.add(3);\n\nmySet.clear();\n\nconsole.log(mySet); \/\/ Set {}\n<\/pre>\n<p>\u4f7f\u7528 TypeScript \u4f86\u64cd\u4f5c Sets \u662f\u4e00\u4ef6\u975e\u5e38\u5bb9\u6613\u7684\u4e8b\u60c5\uff0c\u53ea\u8981\u719f\u6089 Set \u985e\u5225\u63d0\u4f9b\u7684\u65b9\u6cd5\uff0c\u5c31\u53ef\u4ee5\u8f15\u9b06\u5730\u64cd\u4f5c Sets \u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3TypeScript\u4e2d\u7684Sets\u529f\u80fd\uff0cSets\u662f\u4e00\u7a2e\u4e0d\u91cd\u8907\u7684\u503c\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u4f55\u985e\u578b\u7684\u503c\uff0c\u4e26\u63d0\u4f9b\u4e00\u7cfb\u5217\u7684\u64cd\u4f5c\u4f86\u64cd\u4f5c\u9019\u4e9b\u503c\uff0c\u4f8b\u5982\u6dfb\u52a0\u3001\u522a\u9664\u3001\u67e5\u627e\u548c\u66f4\u65b0\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-5448","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-1pS","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5448","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=5448"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5448\/revisions"}],"predecessor-version":[{"id":5449,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5448\/revisions\/5449"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}