{"id":1747,"date":"2024-11-10T12:53:48","date_gmt":"2024-11-10T04:53:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1747\/"},"modified":"2024-11-10T12:53:48","modified_gmt":"2024-11-10T04:53:48","slug":"javascript-%e6%95%b0%e7%bb%84%e9%81%8d%e5%8e%86%ef%bc%9a%e5%a6%82%e4%bd%95%e9%80%89%e6%8b%a9%e6%9c%80%e9%80%82%e5%90%88%e4%bd%a0%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1747\/","title":{"rendered":"JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173054963248723.jpg\" class=\"aligncenter\" title=\"JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>javascript \u6570\u7ec4\u904d\u5386<\/strong><\/p>\n<p>\u672c\u6587\u5c06\u63a2\u8ba8 javascript \u4e2d\u6570\u7ec4\u904d\u5386\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u904d\u5386\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u548c\u64cd\u4f5c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002<\/p>\n<p><strong>\u4f20\u7edf for \u5faa\u73af<\/strong><\/p>\n<p>\u8fd9\u662f\u6700\u5e38\u89c1\u3001\u6700\u7b80\u5355\u7684\u904d\u5386\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>var list = ['one', 'two', 'three'];\n\nfor (var i = 0; i &lt; list.length; i++) {\n  console.log(list[i]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>foreach<\/strong><\/p>\n<p>foreach \u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u3001\u66f4\u5177\u58f0\u660e\u6027\u7684\u904d\u5386\u65b9\u6cd5\u3002\u5b83\u63a5\u53d7\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u8be5\u51fd\u6570\u5728\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0a\u6267\u884c\uff1a<\/p>\n<pre>var list = ['one', 'two', 'three'];\n\nlist.foreach(function(element) {\n  console.log(element);\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>map<\/strong><\/p>\n<p>map \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b\u5bf9\u6bcf\u4e2a\u5143\u7d20\u5e94\u7528\u6307\u5b9a\u51fd\u6570\u7684\u7ed3\u679c\uff1a<\/p>\n<pre>var list = ['one', 'two', 'three'];\n\nvar newlist = list.map(function(element) {\n  return element.touppercase();\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>filter<\/strong><\/p>\n<p>filter \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b\u901a\u8fc7\u6307\u5b9a\u6761\u4ef6\u8fc7\u6ee4\u7684\u5143\u7d20\uff1a<\/p>\n<pre>var list = ['one', 'two', 'three'];\n\nvar newlist = list.filter(function(element) {\n  return element.length === 3;\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>reduce<\/strong><\/p>\n<p>reduce \u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u7d2f\u79ef\u4e3a\u4e00\u4e2a\u5355\u4e00\u503c\uff1a<\/p>\n<pre>var List = [1, 2, 3];\n\nvar sum = List.reduce(function(total, element) {\n  return total + element;\n}, 0);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u6700\u4f73\u7684\u904d\u5386\u65b9\u6cd5\u53d6\u51b3\u4e8e\u6027\u80fd\u548c\u5177\u4f53\u8981\u6c42\u3002\u4f20\u7edf for \u5faa\u73af\u9002\u7528\u4e8e\u4efb\u4f55\u60c5\u51b5\uff0c\u4f46\u901f\u5ea6\u8f83\u6162\u3002foreach\u3001map\u3001filter \u548c reduce \u662f\u66f4\u73b0\u4ee3\u7684\u65b9\u6cd5\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5\u5e76\u63d0\u9ad8\u4e86\u6548\u7387\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\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>javascript \u6570\u7ec4\u904d\u5386 \u672c\u6587\u5c06\u63a2\u8ba8 javascript \u4e2d\u6570\u7ec4\u904d\u5386\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u904d\u5386\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u548c\u64cd\u4f5c\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002 \u4f20\u7edf for \u5faa\u73af \u8fd9\u662f\u6700\u5e38\u89c1\u3001\u6700\u7b80\u5355\u7684\u904d\u5386\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b var list = [&#8216;one&#8217;, &#8216;two&#8217;, &#8216;three&#8217;]; for (var i = 0; i &lt; list.length; i++) { console.log(list[i]); } \u767b\u5f55\u540e\u590d\u5236 foreach foreach \u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u3001\u66f4\u5177\u58f0\u660e\u6027\u7684\u904d\u5386\u65b9\u6cd5\u3002\u5b83\u63a5\u53d7\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u8be5\u51fd\u6570\u5728\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u4e0a\u6267\u884c\uff1a var list = [&#8216;one&#8217;, &#8216;two&#8217;, &#8216;three&#8217;]; list.foreach(function(element) { console.log(element); }); \u767b\u5f55\u540e\u590d\u5236 map map \u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u5176\u4e2d\u5305\u542b\u5bf9\u6bcf\u4e2a\u5143\u7d20\u5e94\u7528\u6307\u5b9a\u51fd\u6570\u7684\u7ed3\u679c\uff1a var list = [&#8216;one&#8217;, &#8216;two&#8217;, &#8216;three&#8217;]; var newlist = [&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-1747","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1747","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=1747"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1747\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}