{"id":2870,"date":"2024-11-10T10:57:09","date_gmt":"2024-11-10T02:57:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2870\/"},"modified":"2024-11-10T10:57:09","modified_gmt":"2024-11-10T02:57:09","slug":"%e8%bf%99%e6%ae%b5%e4%bb%a3%e7%a0%81%e4%b8%ad%e7%9a%84-if-%e8%af%ad%e5%8f%a5%e7%9a%84%e4%bd%9c%e7%94%a8%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2870\/","title":{"rendered":"\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u7684 `if` \u8bed\u53e5\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173089891431915.jpg\" class=\"aligncenter\" title=\"\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u7684 `if` \u8bed\u53e5\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u7684 `if` \u8bed\u53e5\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5212\u7ebf\u7684\u90a3\u6bb5js\u4ee3\u7801\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/strong><\/p>\n<p>\u5728\u7ed9\u5b9a\u7684\u4ee3\u7801\u6bb5\u4e2d\uff0c\u7528\u4e0b\u5212\u7ebf\u6807\u8bb0\u7684\u90e8\u5206\u662f\u4e00\u4e2a\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\uff1a<\/p>\n<pre>&lt;span style=\"text-decoration: underline\"&gt;if&lt;\/span&gt;&lt;span style=\"color: #000000; text-decoration: underline\"&gt; (json) {\n    &lt;\/span&gt;&lt;span style=\"color: #0000ff; text-decoration: underline\"&gt;for&lt;\/span&gt; ( &lt;span style=\"color: #0000ff; text-decoration: underline\"&gt;var&lt;\/span&gt; i = 0; i &lt; json.length; i++&lt;\/span&gt;&lt;span style=\"color: #000000\"&gt;&lt;span style=\"text-decoration: underline\"&gt;) {\n        console.log(json[i].context);\n        arr.push(json[i].user.app_name);\n    }\n&lt;\/span&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b83\u68c0\u67e5 json \u53d8\u91cf\u662f\u5426\u4e3a true\uff0c\u5982\u679c\u662f\uff0c\u5b83\u5c06\u5faa\u73af\u904d\u5386 json \u6570\u7ec4\uff0c\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\u7684\u5185\u5bb9 json[i].context \u5e76\u5c06 json[i].user.app_name \u6dfb\u52a0\u5230 arr \u6570\u7ec4\u4e2d\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u5224\u65ad\u65b9\u5f0f\u5e76\u4e0d\u5e38\u89c1\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528 if (json.length &gt; 0) \u6216 if (json != null) \u6765\u5224\u65ad json \u662f\u5426\u5305\u542b\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u7684 `if` \u8bed\u53e5\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\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>\u5212\u7ebf\u7684\u90a3\u6bb5js\u4ee3\u7801\u662f\u4ec0\u4e48\u610f\u601d\uff1f \u5728\u7ed9\u5b9a\u7684\u4ee3\u7801\u6bb5\u4e2d\uff0c\u7528\u4e0b\u5212\u7ebf\u6807\u8bb0\u7684\u90e8\u5206\u662f\u4e00\u4e2a\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\uff1a &lt;span style=&#8221;text-decoration: underline&#8221;&gt;if&lt;\/span&gt;&lt;span style=&#8221;color: #000000; text-decoration: underline&#8221;&gt; (json) { &lt;\/span&gt;&lt;span style=&#8221;color: #0000ff; text-decoration: underline&#8221;&gt;for&lt;\/span&gt; ( &lt;span style=&#8221;color: #0000ff; text-decoration: underline&#8221;&gt;var&lt;\/span&gt; i = 0; i &lt; json.length; i++&lt;\/span&gt;&lt;span style=&#8221;color: #000000&#8243;&gt;&lt;span style=&#8221;text-decoration: underline&#8221;&gt;) { console.log(json[i].context); arr.push(json[i].user.app_name); } &lt;\/span&gt; \u767b\u5f55\u540e\u590d\u5236 \u5b83\u68c0\u67e5 json \u53d8\u91cf\u662f\u5426\u4e3a true\uff0c\u5982\u679c\u662f\uff0c\u5b83\u5c06\u5faa\u73af\u904d\u5386 json \u6570\u7ec4\uff0c\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\u7684\u5185\u5bb9 json[i].context \u5e76\u5c06 json[i].user.app_name \u6dfb\u52a0\u5230 arr \u6570\u7ec4\u4e2d\u3002 \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u5224\u65ad\u65b9\u5f0f\u5e76\u4e0d\u5e38\u89c1\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528 if (json.length &gt; [&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-2870","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2870","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=2870"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2870\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}