{"id":1443,"date":"2024-11-10T17:32:18","date_gmt":"2024-11-10T09:32:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1443\/"},"modified":"2024-11-10T17:32:18","modified_gmt":"2024-11-10T09:32:18","slug":"%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%95%b0%e7%bb%84%e4%b8%ad%e5%80%bc%e4%b8%ba-null-%e7%9a%84%e5%85%83%e7%b4%a0%e7%9a%84%e9%95%bf%e5%ba%a6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1443\/","title":{"rendered":"\u5982\u4f55\u83b7\u53d6\u6570\u7ec4\u4e2d\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173043542564790.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u83b7\u53d6\u6570\u7ec4\u4e2d\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u83b7\u53d6\u6570\u7ec4\u4e2d\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u83b7\u53d6\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6<\/strong><\/p>\n<p>\u5bf9\u4e8e\u9700\u8981\u8ba1\u7b97\u5177\u6709 null \u503c\u7684\u5143\u7d20\u7684\u6570\u7ec4\u957f\u5ea6\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u9ad8\u9636\u51fd\u6570 filter\u3002\u8be5\u51fd\u6570\u53ef\u4ee5\u8fc7\u6ee4\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff0c\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u7ec4\u6210\u7684\u6570\u7ec4\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 filter \u6c42\u51fa null \u5143\u7d20\u7684\u957f\u5ea6\uff1a<\/p>\n<pre>const array = [1, 2, null, null, 5];\nconst nullElementsCount = array.filter(function(item) {\n  return item === null;\n}).length;\n\nconsole.log(nullElementsCount); \/\/ \u8f93\u51fa\uff1a2<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cfilter \u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u3002\u8be5\u533f\u540d\u51fd\u6570\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a null\uff0c\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002\u7136\u540e\uff0cfilter \u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u5143\u7d20\u7684\u6570\u7ec4\u3002\u6700\u540e\uff0c\u4f7f\u7528 length \u5c5e\u6027\u53ef\u4ee5\u83b7\u5f97\u8be5\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5f97\u5230\u503c\u4e3a null \u7684\u5143\u7d20\u6570\u91cf\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u83b7\u53d6\u6570\u7ec4\u4e2d\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6\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>\u5982\u4f55\u83b7\u53d6\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6 \u5bf9\u4e8e\u9700\u8981\u8ba1\u7b97\u5177\u6709 null \u503c\u7684\u5143\u7d20\u7684\u6570\u7ec4\u957f\u5ea6\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u9ad8\u9636\u51fd\u6570 filter\u3002\u8be5\u51fd\u6570\u53ef\u4ee5\u8fc7\u6ee4\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff0c\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u5143\u7d20\u7ec4\u6210\u7684\u6570\u7ec4\u3002 \u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 filter \u6c42\u51fa null \u5143\u7d20\u7684\u957f\u5ea6\uff1a const array = [1, 2, null, null, 5]; const nullElementsCount = array.filter(function(item) { return item === null; }).length; console.log(nullElementsCount); \/\/ \u8f93\u51fa\uff1a2 \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cfilter \u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u3002\u8be5\u533f\u540d\u51fd\u6570\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a null\uff0c\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002\u7136\u540e\uff0cfilter \u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6240\u6709\u6ee1\u8db3\u8be5\u6761\u4ef6\u7684\u5143\u7d20\u7684\u6570\u7ec4\u3002\u6700\u540e\uff0c\u4f7f\u7528 length \u5c5e\u6027\u53ef\u4ee5\u83b7\u5f97\u8be5\u6570\u7ec4\u7684\u957f\u5ea6\uff0c\u5f97\u5230\u503c\u4e3a null \u7684\u5143\u7d20\u6570\u91cf\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u83b7\u53d6\u6570\u7ec4\u4e2d\u503c\u4e3a null \u7684\u5143\u7d20\u7684\u957f\u5ea6\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1443","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1443","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=1443"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1443\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}