{"id":5058,"date":"2023-01-05T11:46:48","date_gmt":"2023-01-05T03:46:48","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5058"},"modified":"2023-01-05T11:46:48","modified_gmt":"2023-01-05T03:46:48","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e6%95%b8%e7%b5%84%e7%9a%84%e8%bf%ad%e4%bb%a3%e5%99%a8arrayiterators","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e6%95%b8%e7%b5%84%e7%9a%84%e8%bf%ad%e4%bb%a3%e5%99%a8arrayiterators\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u6578\u7d44\u7684\u8fed\u4ee3\u5668(ArrayIterators)"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, \u6578\u7d44\u7684\u8fed\u4ee3\u5668, Array Iterators\"><\/p>\n<h1>TypeScript \u6578\u7d44\u7684\u8fed\u4ee3\u5668(Array Iterators)<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\u548c\u66f4\u591a\u7684\u8a9e\u6cd5\u7d50\u69cb\u3002\u5176\u4e2d\u4e00\u500b\u529f\u80fd\u662f\u6578\u7d44\u7684\u8fed\u4ee3\u5668\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u6578\u7d44\u7684\u8fed\u4ee3\u5668\uff1f<\/h2>\n<p>\u6578\u7d44\u7684\u8fed\u4ee3\u5668\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u51fd\u6578\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002<\/p>\n<h2>TypeScript \u4e2d\u7684\u6578\u7d44\u7684\u8fed\u4ee3\u5668<\/h2>\n<p>TypeScript \u4e2d\u7684\u6578\u7d44\u7684\u8fed\u4ee3\u5668\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u6578\u7d44\u4e2d\u7684\u5143\u7d20\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u7684\u65b9\u6cd5\u4f86\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002<\/p>\n<h3>for&#8230;of \u8ff4\u5708<\/h3>\n<p>TypeScript \u4e2d\u6700\u5e38\u7528\u7684\u6578\u7d44\u7684\u8fed\u4ee3\u5668\u662f for&#8230;of \u8ff4\u5708\u3002\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet arr = [1, 2, 3, 4, 5];\n\nfor (let item of arr) {\n    console.log(item);\n}\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5c07\u6578\u7d44\u4e2d\u7684\u6bcf\u500b\u5143\u7d20\u5370\u51fa\u4f86\u3002<\/p>\n<h3>forEach() \u65b9\u6cd5<\/h3>\n<p>TypeScript \u4e2d\u9084\u6709\u4e00\u500b\u53eb\u505a forEach() \u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002<\/p>\n<pre class=\"brush: typescript\">\nlet arr = [1, 2, 3, 4, 5];\n\narr.forEach(item => {\n    console.log(item);\n});\n<\/pre>\n<p>\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u6703\u5c07\u6578\u7d44\u4e2d\u7684\u6bcf\u500b\u5143\u7d20\u5370\u51fa\u4f86\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>TypeScript \u4e2d\u7684\u6578\u7d44\u7684\u8fed\u4ee3\u5668\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7a2e\u7c21\u55ae\u7684\u65b9\u6cd5\u4f86\u904d\u6b77\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u4f8b\u5982 for&#8230;of \u8ff4\u5708\u548c forEach() \u65b9\u6cd5\u3002<!--more--> \u9019\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u5bb9\u6613\u5730\u64cd\u4f5c\u6578\u7d44\u4e2d\u7684\u5143\u7d20\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52d5\u904d\u6b77\u6bcf\u500b\u5143\u7d20\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3TypeScript\u4e2d\u6578\u7d44\u7684\u8fed\u4ee3\u5668(ArrayIterators)\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u66f4\u6709\u6548\u7387\u7684\u64cd\u4f5c\u6578\u7d44\uff0c\u66f4\u5feb\u901f\u7684\u5b8c\u6210\u958b\u767c\u4efb\u52d9\u3002\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u6578\u7d44\u7684\u8fed\u4ee3\u5668(ArrayIterators)\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u66f4\u6709\u6548\u7387\u7684\u64cd\u4f5c\u6578\u7d44\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-5058","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-1jA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5058","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=5058"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5058\/revisions"}],"predecessor-version":[{"id":5059,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5058\/revisions\/5059"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}