{"id":52640,"date":"2024-12-03T15:34:52","date_gmt":"2024-12-03T07:34:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52640\/"},"modified":"2024-12-03T15:34:52","modified_gmt":"2024-12-03T07:34:52","slug":"%e5%a6%82%e4%bd%95%e7%94%a8javascript%e5%b0%86%e6%95%b0%e7%bb%84%e6%95%b0%e6%8d%ae%e5%90%88%e5%b9%b6%e5%88%b0json%e6%95%b0%e7%bb%84%e4%b8%ad%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52640\/","title":{"rendered":"\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732246970673ffdba4a130.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u6570\u7ec4\u5408\u5e76\u5230 json \u6570\u7ec4\u4e2d<\/strong><\/p>\n<p>\u4e3a\u4e86\u5c06\u6570\u7ec4\u5408\u5e76\u5230 json \u6570\u7ec4\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 javascript \u7684 map() \u65b9\u6cd5\u548c\u5c55\u5f00\u8fd0\u7b97\u7b26 (&#8230;) \u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u4f7f\u7528 map() \u65b9\u6cd5\u904d\u5386 json \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002<\/li>\n<li>\u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26 (&#8230;) \u5c06\u5143\u7d20\u4e0e\u6570\u7ec4\u4e2d\u7684\u76f8\u5e94\u503c\u5408\u5e76\u3002<\/li>\n<li>\u8fd4\u56de\u5408\u5e76\u540e\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u7ed9\u5b9a\u6570\u7ec4 a \u548c json \u6570\u7ec4 b\uff1a<\/p>\n<pre>const a = [111, 222];\nconst b = [\n  { des: \"aaaaa\", value: \"1\" },\n  { des: \"bbbbb\", value: \"2\" },\n];<\/pre>\n<p>\u53ef\u4ee5\u5408\u5e76\u5b83\u4eec\uff1a<\/p>\n<pre>const mergedarray = b.map((v, i) =&gt; ({ ...v, value: `${a[i]}` }));\n\nconsole.log(mergedarray);<\/pre>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[\n  { des: \"aaaaa\", value: \"111\" },\n  { des: \"bbbbb\", value: \"222\" },\n]<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   win10\u6253\u5370\u673a\u600e\u4e48\u8bbe\u7f6e\u9ed8\u8ba4\u8bbe\u5907 win10\u8bbe\u7f6e\u9ed8\u8ba4\u6253\u5370\u673a\u65b9\u6cd5\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5982\u4f55\u7528JavaScript\u5c06\u6570\u7ec4\u6570\u636e\u5408\u5e76\u5230JSON\u6570\u7ec4\u4e2d\uff1f\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u5982\u4f55\u5c06\u6570\u7ec4\u5408\u5e76\u5230 json \u6570\u7ec4\u4e2d \u4e3a\u4e86\u5c06\u6570\u7ec4\u5408\u5e76\u5230 json \u6570\u7ec4\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 javascript \u7684 map() \u65b9\u6cd5\u548c\u5c55\u5f00\u8fd0\u7b97\u7b26 (&#8230;) \u6765\u5b9e\u73b0\u3002 \u6b65\u9aa4\uff1a \u4f7f\u7528 map() \u65b9\u6cd5\u904d\u5386 json \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002 \u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26 (&#8230;) \u5c06\u5143\u7d20\u4e0e\u6570\u7ec4\u4e2d\u7684\u76f8\u5e94\u503c\u5408\u5e76\u3002 \u8fd4\u56de\u5408\u5e76\u540e\u7684\u5bf9\u8c61\u3002 \u793a\u4f8b\uff1a \u7ed9\u5b9a\u6570\u7ec4 a \u548c json \u6570\u7ec4 b\uff1a const a = [111, 222]; const b = [ { des: &#8220;aaaaa&#8221;, value: &#8220;1&#8221; }, { des: &#8220;bbbbb&#8221;, value: &#8220;2&#8221; }, ]; \u53ef\u4ee5\u5408\u5e76\u5b83\u4eec\uff1a const [&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-52640","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52640","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=52640"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52640\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52640"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}