{"id":5210,"date":"2023-01-05T12:12:33","date_gmt":"2023-01-05T04:12:33","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5210"},"modified":"2023-01-05T12:12:33","modified_gmt":"2023-01-05T04:12:33","slug":"%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e6%95%b8%e7%b5%84%e7%9a%84%e6%af%94%e8%bc%83%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e5%ad%b8%e7%bf%92typescript%e4%b8%ad%e6%95%b8%e7%b5%84%e7%9a%84%e6%af%94%e8%bc%83%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u5b78\u7fd2TypeScript\u4e2d\u6578\u7d44\u7684\u6bd4\u8f03\u65b9\u6cd5"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u6578\u7d44\u7684\u6bd4\u8f03, Array Compare\"><\/p>\n<h1>TypeScript \u6578\u7d44\u7684\u6bd4\u8f03(Array Compare)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u985e\u578b\u6aa2\u67e5\u548c\u975c\u614b\u5206\u6790\u529f\u80fd\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u652f\u6301\u958b\u767c\u8005\u958b\u767c\u5927\u578b\u61c9\u7528\u7a0b\u5e8f\u3002\u5728 TypeScript \u4e2d\uff0c\u6578\u7d44\u7684\u6bd4\u8f03\u662f\u4e00\u500b\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u5b83\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u63a7\u5236\u548c\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2>\u6578\u7d44\u7684\u6bd4\u8f03<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0c\u6578\u7d44\u7684\u6bd4\u8f03\u662f\u6307\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\u662f\u5426\u76f8\u7b49\u3002\u5b83\u53ef\u4ee5\u7528\u4f86\u6aa2\u67e5\u5169\u500b\u6578\u7d44\u662f\u5426\u5177\u6709\u76f8\u540c\u7684\u5143\u7d20\uff0c\u6216\u8005\u6aa2\u67e5\u5169\u500b\u6578\u7d44\u662f\u5426\u5177\u6709\u76f8\u540c\u7684\u9806\u5e8f\u3002<\/p>\n<h3>\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20<\/h3>\n<p>\u8981\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>Array.prototype.every()<\/code> \u65b9\u6cd5\u3002\u5b83\u6703\u63a5\u53d7\u4e00\u500b\u56de\u8abf\u51fd\u6578\uff0c\u8a72\u56de\u8abf\u51fd\u6578\u6703\u63a5\u53d7\u5169\u500b\u53c3\u6578\uff0c\u5206\u5225\u662f\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\u3002\u5982\u679c\u5169\u500b\u5143\u7d20\u76f8\u7b49\uff0c\u5247\u8fd4\u56de <code>true<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>false<\/code>\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\uff1a<\/p>\n<pre><code class=\"language-typescript line-numbers\">let arr1 = [1, 2, 3];\nlet arr2 = [1, 2, 3];\n\nlet isEqual = arr1.every((element, index) =&gt; element === arr2[index]);\n\nconsole.log(isEqual); \/\/ true\n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>Array.prototype.every()<\/code> \u65b9\u6cd5\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\u3002\u5982\u679c\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\u76f8\u7b49\uff0c\u5247 <code>isEqual<\/code> \u7684\u503c\u70ba <code>true<\/code>\uff0c\u5426\u5247\u70ba <code>false<\/code>\u3002<\/p>\n<h3>\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u9806\u5e8f<\/h3>\n<p>\u8981\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u9806\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>Array.prototype.every()<\/code> \u65b9\u6cd5\uff0c\u4e26\u5c07 <code>Array.prototype.sort()<\/code> \u65b9\u6cd5\u4f5c\u70ba\u56de\u8abf\u51fd\u6578\u7684\u53c3\u6578\u3002 <code>Array.prototype.sort()<\/code> \u65b9\u6cd5\u6703\u5c0d\u6578\u7d44\u7684\u5143\u7d20\u9032\u884c\u6392\u5e8f\uff0c\u4e26\u8fd4\u56de\u4e00\u500b\u6392\u5e8f\u5f8c\u7684\u6578\u7d44\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u9806\u5e8f\uff1a<\/p>\n<pre><code class=\"language-typescript line-numbers\">let arr1 = [1, 2, 3];\nlet arr2 = [3, 2, 1];\n\nlet isEqual = arr1.every((element, index) =&gt; element === arr2.sort()[index]);\n\nconsole.log(isEqual); \/\/ true\n<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>Array.prototype.every()<\/code> \u65b9\u6cd5\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u9806\u5e8f\u3002\u5982\u679c\u5169\u500b\u6578\u7d44\u7684\u9806\u5e8f\u76f8\u540c\uff0c\u5247 <code>isEqual<\/code> \u7684\u503c\u70ba <code>true<\/code>\uff0c\u5426\u5247\u70ba <code>false<\/code>\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a0e\u8ad6\u4e86 TypeScript \u4e2d\u6578\u7d44\u7684\u6bd4\u8f03\u3002\u6211\u5011\u5b78\u7fd2\u4e86\u5982\u4f55\u4f7f\u7528 <code>Array.prototype.every()<\/code> \u65b9\u6cd5\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\u7684\u5143\u7d20\u548c\u9806\u5e8f\u3002\u901a\u904e\u4f7f\u7528 TypeScript \u4e2d\u7684\u6578\u7d44\u6bd4\u8f03\u529f\u80fd\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u548c\u7ba1\u7406\u6578\u64da\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u6578\u7d44\u7684\u6bd4\u8f03\u65b9\u6cd5\uff0c\u8a73\u7d30\u89e3\u91cb\u5982\u4f55\u4f7f\u7528\u6bd4\u8f03\u51fd\u6578\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u7d44\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u6bd4\u8f03\u51fd\u6578\u4f86\u6bd4\u8f03\u6578\u7d44\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5210","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1m2","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5210"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5210\/revisions"}],"predecessor-version":[{"id":5211,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5210\/revisions\/5211"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}