{"id":336,"date":"2023-10-18T21:49:51","date_gmt":"2023-10-18T13:49:51","guid":{"rendered":"https:\/\/www.qzdd.net\/?p=336"},"modified":"2023-10-18T21:49:51","modified_gmt":"2023-10-18T13:49:51","slug":"%e6%95%b0%e7%bb%84%e8%bf%ad%e4%bb%a3%e5%99%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.qzdd.net\/?p=336","title":{"rendered":"\u6570\u7ec4\u8fed\u4ee3\u5668\u65b9\u6cd5"},"content":{"rendered":"\n<p>forEach((value, index, arr) =&gt;{}, thisArg?)  \u7a00\u758f\u6570\u7ec4\u4e2d\u7684\u7a7a\u767d\u5143\u7d20\u4e0d\u53c2\u4e0e\uff0c\u65e0\u6cd5\u63d0\u524d\u7ed3\u675f\u8fed\u4ee3\u5fc5\u987b\u904d\u5386\u5b8c\u6bd5\uff0c\u65e0\u8fd4\u56de\u503c<\/p>\n\n\n\n<p>map((value, index, arr) =&gt;{}, thisArg?) \u8fd4\u56de\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20\u4e0d\u4f20\u5165\u51fd\u6570\uff0c\u4f46\u6700\u540e\u7684\u7ed3\u679c\u5305\u542b\u7a7a\u767d\u5143\u7d20\uff0c\u8fd4\u56de\u7684\u6570\u7ec4\u957f\u5ea6\u548c\u539f\u6570\u7ec4\u957f\u5ea6\u4e00\u81f4 <\/p>\n\n\n\n<p>filter((value, index, arr) =&gt;{}, thisArg?) \u8fd4\u56de\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3atrue\u771f\u503c\u7684\u5143\u7d20\u7ec4\u6210\u7684\u6570\u7ec4\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20\u4e0d\u4f20\u5165\uff0c\u4e0d\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<p>find((value, index, arr) =>{}, thisArg?) \u8fd4\u56de\u4f7f\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3atrue\u771f\u503c\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20<strong>\u4f20\u5165<\/strong>\uff08\u53ea\u662f\u503c\u4e3aundefined\uff09\uff0c\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<p>findIndex((value, index, arr) =>{}, thisArg?) \u8fd4\u56de\u4f7f\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3atrue\u771f\u503c\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20<strong>\u4f20\u5165<\/strong>\uff0c\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<p>every((value, index, arr) =&gt;{}, thisArg?) \u5982\u679c\u6240\u6709\u5143\u7d20\u90fd\u4f7f\u51fd\u6570\u8fd4\u56de\u503c\u4e3atrue\u771f\u503c\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\uff0c\u4f1a\u77ed\u8def\u63d0\u524d\u8fd4\u56defalse\u7ed3\u675f\u540e\u7eed\u8fed\u4ee3\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20\u4e0d\u4f20\u5165\uff0c\u4e0d\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<p>some((value, index, arr) =&gt;{}, thisArg?) \u5982\u679c\u6709\u4e00\u4e2a\u5143\u7d20\u4f7f\u51fd\u6570\u8fd4\u56de\u503c\u4e3atrue\u771f\u503c\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\uff0c\u4f1a\u77ed\u8def\u63d0\u524d\u8fd4\u56detrue\u7ed3\u675f\u540e\u7eed\u8fed\u4ee3\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20\u4e0d\u4f20\u5165\uff0c\u4e0d\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<p>reduce\/reduceRight((pre, cur) =&gt;{}, init) \u5f52\u4e00\u6570\u7ec4\u5143\u7d20\u4e3a\u4e00\u4e2a\u503c\uff0c\u7a00\u758f\u6570\u7ec4\u7a7a\u767d\u5143\u7d20\u4e0d\u4f20\u5165\uff0c\u4e0d\u5f71\u54cd\u7ed3\u679c<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>\u6570\u7ec4\u53ef\u4ee5\u5305\u542b\u201c\u7a7a\u69fd\u201d\uff08\u7a00\u758f\u6570\u7ec4\uff09\uff0c\u8fd9\u4e0e\u7528\u503c\u00a0<code>undefined<\/code>\u00a0\uff08\u4e0d\u5c5e\u4e8e\u7a00\u758f\u6570\u7ec4\uff09\u586b\u5145\u7684\u69fd\u4e0d\u4e00\u6837\u3002\u7a7a\u69fd\uff08\u7a7a\u767d\u5143\u7d20\uff09\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u5f0f\u4ea7\u751f\uff1a<\/cite><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Array \u6784\u9020\u51fd\u6570\uff1a\nconst a = Array(5); \/\/ &#91; &lt;5 empty items> ]\n\n\/\/ \u6570\u7ec4\u5b57\u9762\u91cf\u4e2d\u7684\u8fde\u7eed\u9017\u53f7\uff1a\nconst b = &#91;1, 2, , , 5]; \/\/ &#91; 1, 2, &lt;2 empty items>, 5 ]\n\n\/\/ \u76f4\u63a5\u7ed9\u5927\u4e8e array.length \u7684\u7d22\u5f15\u8bbe\u7f6e\u503c\u4ee5\u5f62\u6210\u7a7a\u69fd\uff1a\nconst c = &#91;1, 2];\nc&#91;4] = 5; \/\/ &#91; 1, 2, &lt;2 empty items>, 5 ]\n\n\/\/ \u901a\u8fc7\u76f4\u63a5\u8bbe\u7f6e .length \u62c9\u957f\u4e00\u4e2a\u6570\u7ec4\uff1a\nconst d = &#91;1, 2];\nd.length = 5; \/\/ &#91; 1, 2, &lt;3 empty items> ]\n\n\/\/ \u5220\u9664\u4e00\u4e2a\u5143\u7d20\uff1a\nconst e = &#91;1, 2, 3, 4, 5];\ndelete e&#91;2]; \/\/ &#91; 1, 2, &lt;1 empty item>, 4, 5 ]\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>\u5728\u67d0\u4e9b\u64cd\u4f5c\u4e2d\uff0c\u7a7a\u69fd\u7684\u884c\u4e3a\u5c31\u50cf\u5b83\u4eec\u88ab\u586b\u5165\u4e86\u00a0<code>undefined<\/code>\u00a0\u90a3\u6837\u3002<\/cite><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>const arr = &#91;1, 2, , , 5]; \/\/ \u521b\u5efa\u4e00\u4e2a\u7a00\u758f\u6570\u7ec4\n\n\/\/ \u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\nconsole.log(arr&#91;2]); \/\/ undefined\n\n\/\/ For...of\nfor (const i of arr) {\n  console.log(i);\n}\n\n\/\/ \u8f93\u51fa\uff1a1 2 undefined undefined 5\n\n\/\/ \u5c55\u5f00\u8fd0\u7b97\nconst another = &#91;...arr]; \/\/ \"another\" \u4e3a &#91; 1, 2, undefined, undefined, 5 ]\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n<cite>\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u4e5f\u4f1a\u8df3\u8fc7\u7a7a\u69fd\uff08\u7a7a\u767d\uff09\u5143\u7d20<\/cite><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u521b\u5efa\u4e00\u4e2a\u7a00\u758f\u6570\u7ec4\nconst arr = &#91;1, 2, , , 5]; \n\n\/\/ \u5c5e\u6027\u8fed\u4ee3\nconst keys = Object.keys(arr); <strong> \/\/ &#91; '0', '1', '4' ]   \u7f3a2,3<\/strong>\n\nfor (const key in arr) {\n  console.log(key);\n}\n<strong>\/\/ \u8f93\u51fa\uff1a'0' '1' '4'<\/strong>\n\n\/\/ \u5728\u5bf9\u8c61\u4e2d\u4f7f\u7528\u5c55\u5f00\u4f1a\u8df3\u8fc7\uff08\u6570\u7ec4\u4e2d\u4f7f\u7528\u5c55\u5f00\u4e0d\u4f1a\u8df3\u8fc7-\u4f1a\u53d8undefined\uff09\uff0c\u4f7f\u7528\u5c5e\u6027\u679a\u4e3e\uff0c\u800c\u4e0d\u662f\u6570\u7ec4\u7684\u8fed\u4ee3\u5668\nconst objectSpread = { ...arr }; \/\/ { '0': 1, '1': 2, '4': 5 }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>forEach((value, index, arr) =&gt;{}, thisArg?) \u7a00\u758f\u6570\u7ec4\u4e2d\u7684\u7a7a\u767d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[85,93],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-base","tag-85","tag-93"],"_links":{"self":[{"href":"https:\/\/www.qzdd.net\/index.php?rest_route=\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qzdd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qzdd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qzdd.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qzdd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336"}],"version-history":[{"count":0,"href":"https:\/\/www.qzdd.net\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qzdd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qzdd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qzdd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}