{"id":1666,"date":"2024-11-10T16:42:54","date_gmt":"2024-11-10T08:42:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1666\/"},"modified":"2024-11-10T16:42:54","modified_gmt":"2024-11-10T08:42:54","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-javascript-%e4%b8%ad%e4%bb%8e%e6%95%b0%e7%bb%84%e4%b8%ad%e5%88%a0%e9%99%a4%e7%89%b9%e5%ae%9a%e9%a1%b9%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1666\/","title":{"rendered":"\u5982\u4f55\u5728 JavaScript \u4e2d\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u7279\u5b9a\u9879\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173052918716368.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 JavaScript \u4e2d\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u7279\u5b9a\u9879\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 JavaScript \u4e2d\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u7279\u5b9a\u9879\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5728 javascript \u4e2d\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u67d0\u4e2a\u503c\u662f\u5f88\u5e38\u89c1\u7684\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4e0d\u4ec5\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u8fd8\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u50cf\u6570\u7ec4\u4e0a\u7684\u672c\u673a\u65b9\u6cd5\u4e00\u6837\u5b9e\u73b0\u5b83\uff0c\u5e76\u7075\u6d3b\u5730\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5305\u62ec\u5bf9\u8c61\u3001\u57fa\u5143\u548c\u81ea\u5b9a\u4e49\u6bd4\u8f83\u903b\u8f91.<\/p>\n<hr>\n<p>\u5728\u6211\u4eec\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u60f3\u9080\u8bf7\u60a8\u8bbf\u95ee 0dev\uff0c\u4e00\u4e2a\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u7684\u5f00\u6e90\u6570\u636e\u5e73\u53f0\u3002\u4f7f\u7528 0dev \u65e0\u9700\u590d\u6742\u7684 sql \u67e5\u8be2\u5373\u53ef\u8bbf\u95ee\u6570\u636e\uff0c\u65e0\u9700\u4efb\u4f55\u7f16\u7801\u5373\u53ef\uff0c\u65e0\u9700\u4efb\u4f55\u6570\u636e\u79d1\u5b66\u7ecf\u9a8c\u5373\u53ef\u751f\u6210\u89c1\u89e3\u3002<\/p>\n<p> \u5b58\u50a8\u5e93\uff1ahttps:\/\/hub.com\/0dev-hq\/0dev<\/p>\n<hr>\n<p>\u8ba9\u6211\u4eec\u5728 javascript \u6570\u7ec4\u4e0a\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5220\u9664\u65b9\u6cd5\uff0c\u5141\u8bb8\u5b83\u9ed8\u8ba4\u5220\u9664\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u503c\u6216\u6307\u5b9a\u65f6\u5220\u9664\u6240\u6709\u51fa\u73b0\u7684\u503c\u3002\u6b64\u5916\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u6dfb\u52a0\u5bf9\u6bd4\u8f83\u5668\u51fd\u6570\u7684\u652f\u6301\u6765\u589e\u5f3a\u5b83\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u63a7\u5236\u503c\u7684\u5339\u914d\u65b9\u5f0f\u3002<\/p>\n<pre>array.prototype.remove = function(value, removeall = false, comparator = (a, b) =&gt; a === b) {\n  if (removeall) {\n    return this.filter(item =&gt; !comparator(item, value));\n  } else {\n    const index = this.findindex(item =&gt; comparator(item, value));\n    if (index !== -1) this.splice(index, 1); \/\/ remove the item if found\n    return this;\n  }\n};\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2> \u89e3\u91ca <\/h2>\n<h3> array.prototype.remove <\/h3>\n<p>\u5c06remove\u6dfb\u52a0\u5230array.prototype\u4f7f\u5f97\u8be5\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u5728\u4efb\u4f55\u6570\u7ec4\u5b9e\u4f8b\u4e0a\u4f7f\u7528\uff0c\u5c31\u50cfmap\u3001filter\u6216splice\u7b49\u539f\u751f\u65b9\u6cd5\u4e00\u6837\u3002<\/p>\n<h3> \u5168\u90e8\u5220\u9664 <\/h3>\n<p>removeall \u53c2\u6570\u63d0\u4f9b\u4e86\u4e00\u79cd\u63a7\u5236\u65b9\u6cd5\u884c\u4e3a\u7684\u7b80\u5355\u65b9\u6cd5\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cremoveall \u8bbe\u7f6e\u4e3a false\uff0c\u8fd9\u610f\u5473\u7740\u4ec5\u5220\u9664\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u6307\u5b9a\u503c\u3002\u5982\u679cremoveall\u8bbe\u7f6e\u4e3atrue\uff0c\u8be5\u65b9\u6cd5\u5c06\u5220\u9664<strong>\u6240\u6709<\/strong>\u4e2a\u6307\u5b9a\u503c\u7684\u51fa\u73b0\u3002<\/p>\n<h3> \u6bd4\u8f83\u5668 <\/h3>\n<p>\u6bd4\u8f83\u5668\u53c2\u6570\u4e4d\u4e00\u770b\u53ef\u80fd\u770b\u8d77\u6765\u591a\u4f59\uff0c\u4f46\u5b83\u4e3a\u6b64\u65b9\u6cd5\u589e\u52a0\u4e86\u66f4\u591a\u7075\u6d3b\u6027\u3002\u5f53\u4f7f\u7528\u5bf9\u8c61\u6570\u7ec4\u65f6\uff0c\u60a8\u5fc5\u987b\u6839\u636e\u5c5e\u6027\u800c\u4e0d\u662f\u7b80\u5355\u7684\u76f8\u7b49\u6765\u5339\u914d\u503c\uff0c\u8fd9\u5c31\u662f\u6bd4\u8f83\u5668\u53c2\u6570\u6d3e\u4e0a\u7528\u573a\u7684\u5730\u65b9\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u7528\u6237\u5bf9\u8c61\u6570\u7ec4\uff0c\u5e76\u4e14\u60f3\u8981\u5220\u9664\u5177\u6709\u7279\u5b9a\u540d\u79f0\u7684\u7528\u6237\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u6bd4\u8f83\u5668\u51fd\u6570\u6839\u636e name \u5c5e\u6027\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<h2> \u4f7f\u7528\u793a\u4f8b <\/h2>\n<h3> \u5220\u9664\u539f\u59cb\u503c <\/h3>\n<p>\u5bf9\u4e8e\u5177\u6709\u6570\u5b57\u7b49\u539f\u59cb\u503c\u7684\u57fa\u672c\u7528\u4f8b\uff0cremove \u65b9\u6cd5\u53ef\u4ee5\u65e0\u7f1d\u5de5\u4f5c\u3002<\/p>\n<pre>javascriptcopy codelet numbers = [1, 2, 3, 4, 2];\nnumbers = numbers.remove(2); \/\/ removes the first occurrence of 2\nconsole.log(numbers); \/\/ output: [1, 3, 4, 2]\n\nnumbers = numbers.remove(2, true); \/\/ removes all occurrences of 2\nconsole.log(numbers); \/\/ output: [1, 3, 4]\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\uff0cremoveall \u9ed8\u8ba4\u4e3a false\uff0c\u4ec5\u5220\u9664\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u60c5\u51b5\u3002\u5c06removeall\u8bbe\u7f6e\u4e3atrue\u5c06\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u6240\u67092\u3002<\/p>\n<h3> \u4f7f\u7528\u6bd4\u8f83\u5668\u5220\u9664\u5bf9\u8c61 <\/h3>\n<p>\u5904\u7406\u5bf9\u8c61\u6570\u7ec4\u65f6\uff0c\u6bd4\u8f83\u5668\u51fd\u6570\u53ef\u4ee5\u51c6\u786e\u6307\u5b9a\u65b9\u6cd5\u5e94\u5982\u4f55\u8bc6\u522b\u5339\u914d\u3002<\/p>\n<pre>javascriptCopy codelet people = [\n  { id: 1, name: 'Alice' },\n  { id: 2, name: 'Bob' },\n  { id: 3, name: 'Alice' }\n];\n\/\/ Remove all occurrences of objects with the name 'Alice'\npeople = people.remove({ name: 'Alice' }, true, (a, b) =&gt; a.name === b.name);\nconsole.log(people); \n\/\/ Output: [{ id: 2, name: 'Bob' }]\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7f16\u7801\u6109\u5feb\uff01 \ud83d\ude42<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 JavaScript \u4e2d\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u7279\u5b9a\u9879\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>\u5728 javascript \u4e2d\u9700\u8981\u4ece\u6570\u7ec4\u4e2d\u5220\u9664\u67d0\u4e2a\u503c\u662f\u5f88\u5e38\u89c1\u7684\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4e0d\u4ec5\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u8fd8\u5c06\u5411\u60a8\u5c55\u793a\u5982\u4f55\u50cf\u6570\u7ec4\u4e0a\u7684\u672c\u673a\u65b9\u6cd5\u4e00\u6837\u5b9e\u73b0\u5b83\uff0c\u5e76\u7075\u6d3b\u5730\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5305\u62ec\u5bf9\u8c61\u3001\u57fa\u5143\u548c\u81ea\u5b9a\u4e49\u6bd4\u8f83\u903b\u8f91. \u5728\u6211\u4eec\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u60f3\u9080\u8bf7\u60a8\u8bbf\u95ee 0dev\uff0c\u4e00\u4e2a\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u7684\u5f00\u6e90\u6570\u636e\u5e73\u53f0\u3002\u4f7f\u7528 0dev \u65e0\u9700\u590d\u6742\u7684 sql \u67e5\u8be2\u5373\u53ef\u8bbf\u95ee\u6570\u636e\uff0c\u65e0\u9700\u4efb\u4f55\u7f16\u7801\u5373\u53ef\uff0c\u65e0\u9700\u4efb\u4f55\u6570\u636e\u79d1\u5b66\u7ecf\u9a8c\u5373\u53ef\u751f\u6210\u89c1\u89e3\u3002 \u5b58\u50a8\u5e93\uff1ahttps:\/\/hub.com\/0dev-hq\/0dev \u8ba9\u6211\u4eec\u5728 javascript \u6570\u7ec4\u4e0a\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5220\u9664\u65b9\u6cd5\uff0c\u5141\u8bb8\u5b83\u9ed8\u8ba4\u5220\u9664\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u503c\u6216\u6307\u5b9a\u65f6\u5220\u9664\u6240\u6709\u51fa\u73b0\u7684\u503c\u3002\u6b64\u5916\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u6dfb\u52a0\u5bf9\u6bd4\u8f83\u5668\u51fd\u6570\u7684\u652f\u6301\u6765\u589e\u5f3a\u5b83\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u63a7\u5236\u503c\u7684\u5339\u914d\u65b9\u5f0f\u3002 array.prototype.remove = function(value, removeall = false, comparator = (a, b) =&gt; a === b) { if (removeall) { return this.filter(item =&gt; !comparator(item, value)); } else { const index = this.findindex(item =&gt; comparator(item, value)); if (index !== -1) this.splice(index, 1); \/\/ remove the [&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-1666","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1666","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=1666"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1666\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}