{"id":2942,"date":"2024-11-10T11:42:38","date_gmt":"2024-11-10T03:42:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2942\/"},"modified":"2024-11-10T11:42:38","modified_gmt":"2024-11-10T03:42:38","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b0%e7%bb%84%e4%bf%a1%e6%81%af%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%8c%89%e5%b9%b4%e9%be%84%e5%88%86%e7%bb%84%e7%9a%84%e5%b5%8c%e5%a5%97%e5%af%b9%e8%b1%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2942\/","title":{"rendered":"\u5982\u4f55\u5c06\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173094478023217.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6570\u636e\u8f6c\u6362\uff1a\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61<\/strong><\/p>\n<p>\u60f3\u8981\u5c06\u7ed9\u5b9a\u7684\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff0c\u53ef\u4ee5\u501f\u52a9\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<pre>\/\/ \u521d\u59cb\u5316\u76ee\u6807\u6570\u636e\u7ed3\u6784\nlet temp = {};\narr.forEach(item =&gt; {\n    if (!temp[item.age]) {\n        temp[item.age] = [];\n    }\n    temp[item.age].push(item.name);\n});\n\n\/\/ \u8f6c\u6362\u6570\u636e\nlet targetArr = [];\nObject.values(temp).forEach(value =&gt; {\n    value.forEach((name, index) =&gt; {\n        if (!targetArr[index]) {\n            targetArr[index] = {};\n        }\n        Object.keys(temp).forEach(key =&gt; {\n            if (key in targetArr[index]) {\n                return;\n            }\n            targetArr[index][key] = '';\n        });\n        targetArr[index][Object.keys(temp).find(key =&gt; temp[key] === value)] = name;\n    });\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\u540e\uff0ctargetArr\u5c06\u662f\u4e00\u4e2a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff0c\u4e0e\u63d0\u4f9b\u7684\u76ee\u6807\u6570\u636e\u4e00\u81f4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u8f6c\u6362\uff1a\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61 \u60f3\u8981\u5c06\u7ed9\u5b9a\u7684\u6570\u7ec4\u4fe1\u606f\u8f6c\u6362\u4e3a\u6309\u5e74\u9f84\u5206\u7ec4\u7684\u5d4c\u5957\u5bf9\u8c61\uff0c\u53ef\u4ee5\u501f\u52a9\u4ee5\u4e0b\u65b9\u6cd5\uff1a \/\/ \u521d\u59cb\u5316\u76ee\u6807\u6570\u636e\u7ed3\u6784 let temp = {}; arr.forEach(item =&gt; { if (!temp[item.age]) { temp[item.age] = []; } temp[item.age].push(item.name); }); \/\/ \u8f6c\u6362\u6570\u636e let targetArr = []; Object.values(temp).forEach(value =&gt; { value.forEach((name, index) =&gt; { if (!targetArr[index]) { targetArr[index] = {}; } Object.keys(temp).forEach(key =&gt; { if (key in targetArr[index]) { return; } targetArr[index][key] = &#8221;; }); targetArr[index][Object.keys(temp).find(key [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2942","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2942"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2942\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}