{"id":1072,"date":"2023-03-12T10:29:53","date_gmt":"2023-03-12T02:29:53","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1072"},"modified":"2023-04-29T11:44:51","modified_gmt":"2023-04-29T03:44:51","slug":"vue-commonly-used-es6-syntax-data-set-map","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/vue-commonly-used-es6-syntax-data-set-map\/","title":{"rendered":"Vue\u5e38\u7528\u7684ES6\u8bed\u6cd5\u4e4b\u6570\u636e\u96c6\u5408map"},"content":{"rendered":"<p>\u7279\u70b9\uff1a<\/p>\n<ul>\n<li>\u7c7b\u4f3c\u4e8e\u5bf9\u8c61\uff0c\u672c\u8d28\u4e0a\u662f\u952e\u503c\u5bf9\u7684\u96c6\u5408<\/li>\n<li>&quot;\u952e&quot;\u4e0d\u5c40\u9650\u4e8e\u5b57\u7b26\u4e32\uff0c\u5404\u79cd\u7c7b\u578b\u7684\u503c\u90fd\u53ef\u4ee5\u5f53\u4f5c\u952e\uff08\u5305\u62ec\u5bf9\u8c61\uff09<\/li>\n<li>\u5bf9\u8c61&#8217;\u5b57\u7b26\u4e32-\u503c&#8217;\uff0cMap&#8217;\u503c-\u503c&#8217;\u662f\u4e00\u79cd\u66f4\u52a0\u5b8c\u5584\u7684hash\u7ed3\u6784\u4f53\u73b0<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h3>\u521b\u5efa\u4e00\u4e2aMap<\/h3>\n<pre><code class=\"language-javascript\">let obj1 = {a:1}, obj2 = {b:2}; \nconst map = new Map([\n  [&#039;name&#039;, &#039;Joe.Ye&#039;],\n  [&#039;age&#039;, 22],\n  [&#039;sex&#039;, &#039;\u7537&#039;],\n  [obj1, &#039;http:\/\/www.appblog.cn&#039;],\n  [[1,2], &#039;China&#039;],\n  [&#039;age&#039;, 25]\n]); \nconsole.log(map);\nconsole.log(map.size);\/\/5 \u4e5f\u53ef\u4ee5\u7528\u6765\u53bb\u91cd<\/code><\/pre>\n<h3>\u65b9\u6cd5set\u548cget\u3001delete\u3001has\u3001clear<\/h3>\n<pre><code class=\"language-javascript\">map.set([&#039;city&#039;, [&#039;HangZhou&#039;,&#039;ShangHai&#039;]]).set([&#039;country&#039;, [&#039;China&#039;]]); \/\/\u4e3amap\u4e2d\u6dfb\u52a0\u5c5e\u6027\u548c\u503c\nmap.get(&#039;name&#039;); \/\/\u53d6\u503c\nmap.delete(obj1); \/\/\u5220\u9664\n\n \/\/\u6ce8\u610f\u4e8b\u9879\nmap.set({}, &#039;Joe.Ye&#039;);\nmap.set({}, &#039;AppBlog.CN&#039;);\/\/\u8fd9\u5728map\u4e2d\u6dfb\u52a0\u4e86\u4e24\u4e2a\u5bf9\u8c61\uff0c\u56e0\u4e3a\u5bf9\u8c61\u662f\u4e2a\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f1a\u5728\u6808\u91cc\u5f00\u8f9f\u5730\u5740\uff0c\u5728\u5806\u91cc\u5b58\u653e\u503c<\/code><\/pre>\n<h3>keys() values() entries()<\/h3>\n<pre><code class=\"language-javascript\">map.keys(); \/\/\u53d6\u952e\nmap.values(); \/\/\u53d6\u503c\nmap.entries(); \/\/\u53d6\u952e\u503c<\/code><\/pre>\n<h3>\u904d\u5386<\/h3>\n<pre><code class=\"language-javascript\">map.forEach(function(value,index) {\n  console.log(index + &#039;: &#039; + value);\n})<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7279\u70b9\uff1a \u7c7b\u4f3c\u4e8e\u5bf9\u8c61\uff0c\u672c\u8d28\u4e0a\u662f\u952e\u503c\u5bf9\u7684\u96c6\u5408 &quot;\u952e&quot;\u4e0d\u5c40\u9650\u4e8e\u5b57\u7b26\u4e32\uff0c\u5404\u79cd\u7c7b\u578b\u7684\u503c\u90fd\u53ef\u4ee5\u5f53\u4f5c\u952e\uff08 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[295],"class_list":["post-1072","post","type-post","status-publish","format-standard","hentry","category-node","tag-eslint"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1072"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1072\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}