{"id":52624,"date":"2024-12-03T17:06:17","date_gmt":"2024-12-03T09:06:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52624\/"},"modified":"2024-12-03T17:06:17","modified_gmt":"2024-12-03T09:06:17","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52624\/","title":{"rendered":"JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732239749673fe18527b74.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<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><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><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><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><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><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\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u4f7f\u7528 Diffuser \u8fd0\u884c Fluxn Mac\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300aJavaScript \u6570\u7ec4\u904d\u5386\uff1a\u5982\u4f55\u9009\u62e9\u6700\u9002\u5408\u4f60\u7684\u65b9\u6cd5\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 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 var list = [&#8216;one&#8217;, &#8216;two&#8217;, &#8216;three&#8217;]; for (var i = 0; i &lt; list.length; i++) { console.log(list[i]); } 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); }); 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-52624","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52624","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=52624"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52624\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}