{"id":1479,"date":"2024-11-10T11:57:42","date_gmt":"2024-11-10T03:57:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1479\/"},"modified":"2024-11-10T11:57:42","modified_gmt":"2024-11-10T03:57:42","slug":"js%e9%9a%8f%e6%9c%ba%e6%95%b0%e9%87%8d%e5%a4%8d%e7%94%9f%e6%88%90%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e9%87%8d%e5%a4%8d%e7%94%9f%e6%88%90","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1479\/","title":{"rendered":"JS\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u907f\u514d\u91cd\u590d\u751f\u6210\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173044567975513.jpg\" class=\"aligncenter\" title=\"JS\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u907f\u514d\u91cd\u590d\u751f\u6210\uff1f\u63d2\u56fe\" alt=\"JS\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u907f\u514d\u91cd\u590d\u751f\u6210\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528math.random()\u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u65f6\uff0c\u6709\u65f6\u4f1a\u51fa\u73b0\u968f\u673a\u6570\u91cd\u590d\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>const arr = [];\nfor (let i = 0; i &lt; 2; i++) {\n  const el = math.random();\n  const practical = math.random();\n  arr.push({ el, practical });\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cel.expect\u548cpractical\u7684\u503c\u5c06\u76f8\u540c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u5728\u6bcf\u6b21\u751f\u6210\u968f\u673a\u6570\u4e4b\u524d\u66f4\u65b0\u968f\u673a\u79cd\u5b50\uff0c\u786e\u4fdd\u6bcf\u6b21\u751f\u6210\u4e0d\u540c\u7684\u6570\u5b57\u3002\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5728\u5faa\u73af\u5185\u90e8\u4f7f\u7528math.random()\u51fd\u6570\uff1a<\/p>\n<pre>const arr = [];\nfor (let i = 0; i &lt; 2; i++) {\n  const el = Math.random();\n  Math.random();\n  const practical = Math.random();\n  arr.push({ el, practical });\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u5c06\u786e\u4fdd\u6bcf\u6b21\u751f\u6210\u4e0d\u540c\u7684\u968f\u673a\u6570\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJS\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u907f\u514d\u91cd\u590d\u751f\u6210\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>js\u968f\u673a\u6570\u91cd\u590d\u751f\u6210\u7684\u95ee\u9898 \u5728\u4f7f\u7528math.random()\u51fd\u6570\u751f\u6210\u968f\u673a\u6570\u65f6\uff0c\u6709\u65f6\u4f1a\u51fa\u73b0\u968f\u673a\u6570\u91cd\u590d\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff1a const arr = []; for (let i = 0; i &lt; 2; i++) { const el = math.random(); const practical = math.random(); arr.push({ el, practical }); } \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cel.expect\u548cpractical\u7684\u503c\u5c06\u76f8\u540c\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u5728\u6bcf\u6b21\u751f\u6210\u968f\u673a\u6570\u4e4b\u524d\u66f4\u65b0\u968f\u673a\u79cd\u5b50\uff0c\u786e\u4fdd\u6bcf\u6b21\u751f\u6210\u4e0d\u540c\u7684\u6570\u5b57\u3002\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5728\u5faa\u73af\u5185\u90e8\u4f7f\u7528math.random()\u51fd\u6570\uff1a const arr = []; for (let i = 0; i &lt; 2; i++) { const el = Math.random(); Math.random(); const practical = Math.random(); arr.push({ [&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-1479","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1479","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=1479"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1479\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}