{"id":11522,"date":"2025-02-10T21:46:12","date_gmt":"2025-02-10T13:46:12","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11522"},"modified":"2025-02-10T21:46:12","modified_gmt":"2025-02-10T13:46:12","slug":"js-set-intersection-union-difference","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2025\/02\/js-set-intersection-union-difference\/","title":{"rendered":"JS Set\u65b0\u652f\u6301\u4e86intersection, union, difference\u7b49\u65b9\u6cd5"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11522\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11522<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u72ec\u7acb\u57df\u540d\u4e2a\u4eba\u7f51\u7ad9\u65e0\u9700\u6388\u6743\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u3001\u51fa\u5904\u4ee5\u53ca\u6587\u4e2d\u94fe\u63a5\uff0c\u4efb\u4f55\u7f51\u7ad9\u5747\u53ef\u6458\u8981\u805a\u5408\uff0c\u5546\u7528\u8bf7\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202502-js-set.jpg';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/js-set-cover-s.png\" width=\"480\" height=\"300\" alt=\"JS SET API\u5360\u4f4d\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<p>\u7ee7\u7eed\u4ecb\u7ecd\u524d\u7aef\u524d\u6cbf\u65b0\u7279\u6027\uff0c\u4eca\u5929\u8bb2\u7684\u662fSet\u6216\u8005\u7c7b\u4f3cSet\u7684\u6570\u636e\u65b0\u652f\u6301\u7684\u82e5\u5e72\u65b9\u6cd5\uff0c\u4e3b\u8981\u662f\u4ea4\u96c6\u3001\u5408\u96c6\u4ee5\u53ca\u5dee\u5f02\u5224\u5b9a\u76f8\u5173\uff0cAPI\u8f83\u591a\uff0c\u4e00\u4e2a\u4e00\u4e2a\u6765\u3002<\/p>\n<h3>\u4e00\u3001intersection\u4ea4\u96c6<\/h3>\n<p>\u5355\u8bcd&#8217;intersection&#8217;\u5c31\u662f\u4ea4\u53c9\uff0c\u4ea4\u96c6\u7684\u610f\u601d\u3002<\/p>\n<p>\u7528\u6570\u5b66\u516c\u5f0f\u8868\u793a\u5c31\u662f\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u2229<\/mo><mi>B<\/mi><mo>=<\/mo><mo stretchy=\"false\">{<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>A<\/mi><mo>\u2223<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>B<\/mi><mo stretchy=\"false\">}<\/mo><\/mrow><annotation encoding=\"TeX\">A\\cap B = \\{x\\in A\\mid x\\in B\\}<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u7528\u66f4\u76f4\u89c2\u7684\u56fe\u5f62\u8868\u793a\u5219\u4e3a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_141229.png\" width=\"225\" height=\"150\" alt=\"\u4ea4\u96c6\u56fe\u5f62\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u5e94\u7528\u4e3e\u4f8b<\/h4>\n<p>\u5df2\u77e5\u6570\u7ec4A\u548c\u6570\u7ec4B\uff0c\u8bf7\u8fd4\u56de\u4e24\u4e2a\u6570\u7ec4\u76f8\u540c\u7684\u6570\u7ec4\u9879\u3002<\/p>\n<p>\u5728\u8fc7\u53bb\uff0c\u662f\u9700\u8981\u5bf9\u4e24\u4e2a\u6570\u7ec4\u5206\u522b\u5faa\u73af\u5904\u7406\uff0c\u73b0\u5728\u5c31\u662f\u4e00\u884c\u4ee3\u7801\u7684\u4e8b\u60c5\uff0c\u53c2\u8003\u5b9e\u73b0\uff1a<\/p>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u76f8\u540c\u6570\u7ec4\u9879\r\nconsole.log([...new Set(arr1).intersection(new Set(arr2))]);\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1a\r\n\/\/ ['CSS\u65b0\u4e16\u754c']<\/pre>\n<p>\u4f8b\u5982\uff0c\u5728Chrome console\u63a7\u5236\u53f0\u7684\u8fd0\u884c\u7ed3\u679c\u622a\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_160447.png\" width=\"457\" height=\"137\" alt=\"\u6570\u7ec4\u5408\u5e76\u8fd0\u884c\u7ed3\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e8c\u3001union\u5408\u96c6<\/h3>\n<p><code>union()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u8ba9Set\u6216\u8005\u7c7bSet\u5bf9\u8c61\u7684\u503c\u8fdb\u884c\u5408\u5e76\uff08\u540c\u65f6\u53bb\u91cd\uff09\u5904\u7406\u3002<\/p>\n<p>\u8bed\u6cd5\u793a\u610f\uff1a<\/p>\n<pre>set1.union(set2)<\/pre>\n<p>\u6570\u5b66\u516c\u5f0f\u8868\u793a\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u222a<\/mo><mi>B<\/mi><mo>=<\/mo><mo stretchy=\"false\">{<\/mo><mi>x<\/mi><mo>\u2223<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>A<\/mi><mtext>&nbsp;or&nbsp;<\/mtext><mi>x<\/mi><mo>\u220a<\/mo><mi>B<\/mi><mo stretchy=\"false\">}<\/mo><\/mrow><annotation encoding=\"TeX\">A\\cup B = \\{x\\midx\\in A\\text{ or }x\\in B\\}<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u56fe\u5f62\u8868\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_161201.png\" width=\"225\" height=\"150\" alt=\"\u5408\u96c6\u6548\u679c\u56fe\u5f62\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u6848\u4f8b\u793a\u610f<\/h4>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u5408\u5e76\u53bb\u91cd\r\nconsole.log([...new Set(arr1).union(new Set(arr2))]);\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1a\r\n\/\/ ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355', 'CSS\u9009\u62e9\u5668\u4e16\u754c']<\/pre>\n<p>\u4e0b\u56fe\u6240\u793a\u7684\u5c31\u662f\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_162829.png\" width=\"438\" height=\"162\" alt=\"\u6570\u7ec4\u5408\u5e76\u53bb\u91cd\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e09\u3001difference\u548csymmetricDifference\u5dee\u96c6<\/h3>\n<p>Set.prototype.difference()\u8fd4\u56de\u7684\u662f\u53e6\u5916\u4e00\u4e2aSet\u5bf9\u8c61\u548c\u81ea\u8eab\u4e0d\u540c\u7684\u90e8\u5206\u3002<\/p>\n<p>\u7528MathML\u6570\u5b66\u8868\u8fbe\u5f0f\u793a\u610f\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u2216<\/mo><mi>B<\/mi><mo>=<\/mo><mo stretchy=\"false\">{<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>A<\/mi><mo>\u2223<\/mo><mi>x<\/mi><mo>\u2209<\/mo><mi>B<\/mi><mo stretchy=\"false\">}<\/mo><\/mrow><annotation encoding=\"TeX\">A\\setminus B = \\{x\\in A\\mid x\\notin B\\}<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u8fd8\u662f\u4e0b\u9762\u7684\u5706\u5f62\u56fe\u50cf\u66f4\u76f4\u89c2\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_163152.png\" width=\"225\" height=\"150\" alt=\"Set\u5dee\u96c6\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>Example &#8211; \u6848\u4f8b<\/h4>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u8fd4\u56de\u4e0d\u4e00\u6837\u7684\u90e8\u5206\r\nconsole.log([...new Set(arr1).difference(new Set(arr2))]);\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1a\r\n\/\/ ['CSS\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355']<\/pre>\n<p>\u968f\u610f\u6253\u5f00\u4e00\u4e2a\u9875\u9762\u7684console\u8f93\u5165\u6846\uff0c\u7c98\u8d34\u56de\u8f66\u6d4b\u8bd5\u4e0b\uff0c\u679c\u7136\u662f\u8fd9\u4e2a\u8f93\u51fa\u5185\u5bb9\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_163503.png\" width=\"436\" height=\"136\" alt=\"difference\u6848\u4f8b\u8fd0\u884c\u7ed3\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6ce8\u610f\uff0c\u8fd4\u56de\u7684\u662f\u8c03\u7528\u5bf9\u8c61\u7684\u5dee\u503c\uff0c\u800c\u4e0d\u662f\u6240\u6709\u5bf9\u8c61\u4e0d\u540c\u7684\u90e8\u5206\u3002<\/p>\n<p>\u5982\u679c\u60f3\u8981\u53d6\u6240\u6709\u5bf9\u8c61\u7684\u5dee\u503c\u90e8\u5206\uff0c\u8bf7\u4f7f\u7528<code>symmetricDifference()<\/code>\u65b9\u6cd5\u3002<\/p>\n<h4>symmetricDifference\u5bf9\u79f0\u5dee\u96c6<\/h4>\n<p>\u516c\u5f0f\u548c\u56fe\u793a\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u2296<\/mo><mi>B<\/mi><mo>=<\/mo><mo stretchy=\"false\">(<\/mo><mi>A<\/mi><mo>\u2216<\/mo><mi>B<\/mi><mo stretchy=\"false\">)<\/mo><mo>\u222a<\/mo><mo stretchy=\"false\">(<\/mo><mi>B<\/mi><mo>\u2216<\/mo><mi>A<\/mi><mo stretchy=\"false\">)<\/mo><\/mrow><annotation encoding=\"TeX\">A\\ominus B = (A\\setminus B)\\cup(B\\setminus A)<\/annotation><\/semantics>\n<\/math><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_201618.png\" width=\"225\" height=\"150\" alt=\"\u5bf9\u79f0\u5dee\u96c6\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u8fd4\u56de\u4e0d\u4e00\u6837\u7684\u90e8\u5206\r\nconsole.log([...new Set(arr1).symmetricDifference(new Set(arr2))]);\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1a\r\n\/\/ ['CSS\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355', 'CSS\u9009\u62e9\u5668\u4e16\u754c']<\/pre>\n<h3>\u56db\u3001isDisjointFrom()\u662f\u5426\u65e0\u91cd\u5408<\/h3>\n<p>Set\u5bf9\u8c61\u8fd8\u652f\u6301\u4e86\u4e09\u4e2a\u903b\u8f91\u5224\u65ad\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u9996\u5148\u662f<code>isDisjointFrom()<\/code>\u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65adSet\u96c6\u662f\u4e0d\u662f\u6ca1\u6709\u4efb\u4f55\u91cd\u5408\uff0c\u4e5f\u5c31\u662f\u662f\u4e0d\u662f\u6ca1\u6709\u4ea4\u96c6\uff0c\u5355\u8bcddisjoint\u7684\u610f\u601d\u5c31\u662f\u201c\u4e0d\u76f8\u4ea4\uff1b\u76f8\u79bb\uff1b\u201d\u3002<\/p>\n<p>\u7528\u6570\u5b66\u7b26\u53f7\u8868\u793a\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mtext>&nbsp;is disjoint from&nbsp;<\/mtext><mi>B<\/mi><mo stretchy=\"false\">\u21d4<\/mo><mi>A<\/mi><mo>\u2229<\/mo><mi>B<\/mi><mo>=<\/mo><mi>\u2205<\/mi><\/mrow><annotation encoding=\"TeX\">A\\text{ is disjoint from }B \\Leftrightarrow A\\cap B = \\empty<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u4f7f\u7528\u7ef4\u6069\u56fe\u8868\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_195640.png\" width=\"225\" height=\"150\" alt=\"\u4e0d\u76f8\u4ea4\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u4e3e\u4e2a\u4f8b\u5b50<\/h4>\n<p>\u4e0b\u9762arr1\u548carr2\u90fd\u6709\u76f8\u540c\u7684\u6570\u7ec4\u9879<code>'CSS\u65b0\u4e16\u754c'<\/code>\uff0c\u56e0\u6b64\uff0c\u6700\u540e\u8f93\u51fa\u7684\u503c\u5c31\u662ffalse\uff0c\u662f\u6709\u76f8\u540c\u7684\u503c\uff0c\u5f7c\u6b64\u662f\u6709\u76f8\u4ea4\u7684\u3002<\/p>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'CSS\u65b0\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u662f\u5426\u5f7c\u6b64\u72ec\u7acb\r\nconsole.log(new Set(arr1).isDisjointFrom(new Set(arr2)));\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1afalse<\/pre>\n<p>\u4f46\u5982\u679c\u5c06\u6570\u7ec4arr1\u91cc\u9762\u7684\u6570\u7ec4\u9879<code>'CSS\u65b0\u4e16\u754c'<\/code>\u53bb\u6389\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5c31\u4f1a\u4f7ftrue\uff0c\u4e24\u4e2a\u6570\u7ec4\u6ca1\u6709\u4efb\u4f55\u9879\u76ee\u662f\u91cd\u590d\u7684\u3002<\/p>\n<pre>const arr1 = ['CSS\u4e16\u754c', 'HTML\u5e76\u4e0d\u7b80\u5355'];\r\nconst arr2 = ['CSS\u9009\u62e9\u5668\u4e16\u754c', 'CSS\u65b0\u4e16\u754c'];\r\n\/\/ \u662f\u5426\u5f7c\u6b64\u72ec\u7acb\r\nconsole.log(new Set(arr1).isDisjointFrom(new Set(arr2)));\r\n\/\/ \u8fd4\u56de\u7ed3\u679c\u662f\uff1atrue<\/pre>\n<h3>\u4e94\u3001isSubsetOf()\u662f\u5426\u88ab\u5305\u542b<\/h3>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>setA.isSubsetOf(setB)<\/pre>\n<p>\u8868\u793asetA\u662f\u5426\u88absetB\u5305\u542b\u3002<\/p>\n<p>\u7528\u4e13\u95e8\u7684\u6570\u5b66\u7b26\u53f7\u516c\u5f0f\u8868\u793a\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u2286<\/mo><mi>B<\/mi><mo stretchy=\"false\">\u21d4<\/mo><mo>\u2200<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>A<\/mi><mo>,<\/mo><mspace width=\"0.16666666666666666em\"><\/mspace><mi>x<\/mi><mo>\u220a<\/mo><mi>B<\/mi><\/mrow><annotation encoding=\"TeX\">A\\subseteq B \\Leftrightarrow \\forall x\\in A,\\,x\\in B<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u7528\u903b\u8f91\u5173\u7cfb\u56fe\u8868\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_200318.png\" width=\"225\" height=\"150\" alt=\"\u88ab\u5305\u542b\u5173\u7cfb\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<h4>\u6848\u4f8b\u6f14\u793a<\/h4>\n<p>\u5305\u542b\u4e8e\u88ab\u5305\u542b\u8fd8\u662f\u5f88\u597d\u7406\u89e3\u7684\uff0c\u5c31\u662f\u662f\u4e0d\u662f\u6240\u6709A\u7684\u503c\u90fd\u5728B\u91cc\u9762\u3002<\/p>\n<p>\u4e0b\u9762\u662fMDN\u4e0a\u7684\u4f8b\u5b50\uff0c\u8bf7\u770b\uff1a<\/p>\n<pre>const fours = new Set([4, 8, 12, 16]);\r\nconst evens = new Set([2, 4, 6, 8, 10, 12, 14, 16, 18]);\r\nconsole.log(fours.isSubsetOf(evens)); \/\/ true<\/pre>\n<pre>const primes = new Set([2, 3, 5, 7, 11, 13, 17, 19]);\r\nconst odds = new Set([3, 5, 7, 9, 11, 13, 15, 17, 19]);\r\nconsole.log(primes.isSubsetOf(odds)); \/\/ false<\/pre>\n<p>\u5982\u679c\u4e24\u4e2a\u6570\u7ec4\u662f\u4e00\u6837\u7684\uff0c\u90a3\u4e48\u5982\u679c\u8c01\u5305\u542b\u8c01\uff0c\u90fd\u53ef\u4ee5\u8ba4\u4e3a\u662ftrue\uff0c\u6bd4\u65b9\u8bf4\uff1a<\/p>\n<pre>const set1 = new Set([1, 2, 3]);\r\nconst set2 = new Set([1, 2, 3]);\r\nconsole.log(set1.isSubsetOf(set2)); \/\/ true\r\nconsole.log(set2.isSubsetOf(set1)); \/\/ true<\/pre>\n<h3>\u516d\u3001isSupersetOf()\u662f\u5426\u5305\u542b<\/h3>\n<p><code>isSupersetOf()<\/code>\u8868\u793a\u8c03\u7528\u7684Set\u5bf9\u8c61\u662f\u5426\u5305\u542b\u88ab\u8c03\u7528\u7684Set\u5bf9\u8c61\u3002<\/p>\n<p>\u6570\u5b66\u7b26\u53f7\u8868\u793a\u5176\u903b\u8f91\u5173\u7cfb\uff1a<\/p>\n<p><math display=\"block\">\n  <semantics><mrow><mi>A<\/mi><mo>\u2287<\/mo><mi>B<\/mi><mo stretchy=\"false\">\u21d4<\/mo><mo>\u2200<\/mo><mi>x<\/mi><mo>\u220a<\/mo><mi>B<\/mi><mo>,<\/mo><mspace width=\"0.16666666666666666em\"><\/mspace><mi>x<\/mi><mo>\u220a<\/mo><mi>A<\/mi><\/mrow><annotation encoding=\"TeX\">A\\supseteq B \\Leftrightarrow \\forall x\\in B,\\,x\\in A<\/annotation><\/semantics>\n<\/math><\/p>\n<p>\u6216\u662f\u4f7f\u7528Venn\u56fe\u8868\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_200727.png\" width=\"225\" height=\"150\" alt=\"\u5305\u542b\u5173\u7cfb\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u81f3\u4e8e\u6848\u4f8b\uff0c\u548c<code>isSubsetOf()<\/code>\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u8fd9\u91cc\u5c31\u4e0d\u91cd\u590d\u5c55\u793a\u4e86\u3002<\/p>\n<h3>\u4e03\u3001\u517c\u5bb9\u6027\u3001polyfill\u7b49<\/h3>\n<p>\u672c\u6587\u6240\u4ecb\u7ecd\u76846\u4e2aSet\u65b9\u6cd5\uff0c\u5176\u517c\u5bb9\u6027\u90fd\u662f\u4e00\u6837\u7684\uff0c\u6d4f\u89c8\u5668\u540c\u65f6\u652f\u6301\u7684\uff0c\u8fd8\u7b97\u6bd4\u8f83\u65b0\u7684\u65b9\u6cd5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_201009.png\" width=\"647\" height=\"317\" alt=\"Set\u65b0\u65b9\u6cd5\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u7531\u4e8e\u8fd9\u51e0\u4e2a\u65b9\u6cd5\uff0c\u6d4f\u89c8\u5668\u652f\u6301\u7684\u65f6\u95f4\u8fd8\u4e0d\u7b97\u5f88\u957f\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u8981\u5728\u751f\u4ea7\u73af\u5883\u4f7f\u7528\uff0c\u5efa\u8bae\u5f15\u5165Polyfill\u6216\u8005shim\u3002<\/p>\n<p>Polyfill\u5730\u5740\uff1a<a href=\"https:\/\/github.com\/zloirock\/core-js#new-set-methods\">https:\/\/github.com\/zloirock\/core-js#new-set-methods<\/a><br \/>\nShim\u5730\u5740\uff1a<a href=\"https:\/\/github.com\/rauschma\/set-methods-polyfill\">https:\/\/github.com\/rauschma\/set-methods-polyfill<\/a><\/p>\n<h4>\u5176\u4ed6<\/h4>\n<p>\u540c\u4e8b\u9646\u7eed\u5f52\u4e3a\uff0c\u4ece\u4eca\u5929\u5f00\u59cb\uff0c\u6b63\u5f0f\u8fdb\u5165\u5de5\u4f5c\u72b6\u6001\u3002<\/p>\n<p>2025\u5e74\u554a\uff0c\u4e09\u4ef6\u4e8b\u60c5\uff0c\u5199\u5c0f\u8bf4\uff0c\u6301\u7eed\u524d\u7aef\u4e13\u4e1a\u8f93\u51fa\uff0c\u4ee5\u53ca\u9493\u9c7c\u8bb0\u5f55\u3002<\/p>\n<p>\u6301\u4e4b\u4ee5\u6052\uff0c\u9759\u5f85\u5f00\u82b1\u7ed3\u679c\u3002<\/p>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce<button onclick=\"shareWeixin.click()\" class=\"entry-share-btn\">\u5206\u4eab<\/button>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/2025-2-10_213155.jpeg\" width=\"96\" height=\"54\" alt=\"\u54ea\u5412\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=11522\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=11522<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202502\/js-set-cover-s.png\" width=\"160\" height=\"100\" alt=\"JS SET API\u5360\u4f4d\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>JS Set\u5bf9\u8c61\u53c8\u65b0\u589e\u4e86N\u591a\u7684API\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u8c61\u6216\u6570\u7ec4\u53d6\u4ea4\u96c6\u3001\u5408\u96c6\u548c\u5dee\u96c6\uff0c\u4ee5\u53ca\u5224\u65ad\u5305\u542b\u4e0e\u5426\u5173\u7cfb\u7684\u529f\u80fd\uff0c\u90fd\u662f\u6bd4\u8f83\u4f7f\u7528\u7684API\u7279\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[1887,1237,775,2039],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11522"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=11522"}],"version-history":[{"count":8,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11522\/revisions"}],"predecessor-version":[{"id":11591,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/11522\/revisions\/11591"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=11522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=11522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=11522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}