{"id":4856,"date":"2023-01-05T11:04:45","date_gmt":"2023-01-05T03:04:45","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4856"},"modified":"2023-01-05T11:04:45","modified_gmt":"2023-01-05T03:04:45","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e6%95%b8%e7%b5%84arrays%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5%e8%88%87%e6%87%89%e7%94%a8","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e6%95%b8%e7%b5%84arrays%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5%e8%88%87%e6%87%89%e7%94%a8\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u6578\u7d44(Arrays)\u7684\u57fa\u672c\u6982\u5ff5\u8207\u61c9\u7528"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, Arrays\"><\/p>\n<h1>TypeScript \u6578\u7d44(Arrays)\u4ecb\u7d39<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709\u66f4\u591a\u7684\u529f\u80fd\uff0c\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f\u652f\u63f4\u6578\u7d44(Arrays)\u3002\u6578\u7d44\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u5b83\u53ef\u4ee5\u5132\u5b58\u591a\u500b\u503c\uff0c\u4e26\u4e14\u53ef\u4ee5\u900f\u904e\u7d22\u5f15\u4f86\u5b58\u53d6\u9019\u4e9b\u503c\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">Array<\/span> \u985e\u5225\u4f86\u5efa\u7acb\u6578\u7d44\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">push()<\/span> \u65b9\u6cd5\u4f86\u65b0\u589e\u5143\u7d20\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">pop()<\/span> \u65b9\u6cd5\u4f86\u79fb\u9664\u5143\u7d20\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">shift()<\/span> \u65b9\u6cd5\u4f86\u79fb\u9664\u7b2c\u4e00\u500b\u5143\u7d20\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">unshift()<\/span> \u65b9\u6cd5\u4f86\u65b0\u589e\u5143\u7d20\u5230\u7b2c\u4e00\u500b\u4f4d\u7f6e\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">splice()<\/span> \u65b9\u6cd5\u4f86\u79fb\u9664\u6216\u65b0\u589e\u5143\u7d20\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">sort()<\/span> \u65b9\u6cd5\u4f86\u6392\u5e8f\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">reverse()<\/span> \u65b9\u6cd5\u4f86\u53cd\u8f49\u9806\u5e8f\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">indexOf()<\/span> \u65b9\u6cd5\u4f86\u641c\u5c0b\u5143\u7d20\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">forEach()<\/span> \u65b9\u6cd5\u4f86\u8fed\u4ee3\u6578\u7d44\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">map()<\/span> \u65b9\u6cd5\u4f86\u8f49\u63db\u6578\u7d44\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">filter()<\/span> \u65b9\u6cd5\u4f86\u7be9\u9078\u6578\u7d44\uff0c\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">reduce()<\/span> \u65b9\u6cd5\u4f86\u8a08\u7b97\u6578\u7d44\uff0c\u4ee5\u53ca\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">concat()<\/span> \u65b9\u6cd5\u4f86\u5408\u4f75\u6578\u7d44\u7b49\u7b49\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 TypeScript \u4f86\u5efa\u7acb\u4e00\u500b\u6578\u7d44\uff0c\u4e26\u4e14\u65b0\u589e\u5143\u7d20\u5230\u6578\u7d44\u4e2d\uff1a<\/p>\n<pre class=\"brush: typescript\">\nlet numbers: number[] = [1, 2, 3];\n\nnumbers.push(4);\n\nconsole.log(numbers); \/\/ [1, 2, 3, 4]\n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5148\u5ba3\u544a\u4e00\u500b <span style=\"color: #009900; font-weight: bold;\">numbers<\/span> \u8b8a\u6578\uff0c\u4e26\u4e14\u6307\u5b9a\u5b83\u7684\u578b\u5225\u70ba <span style=\"color: #009900; font-weight: bold;\">number[]<\/span>\uff0c\u8868\u793a\u5b83\u662f\u4e00\u500b\u6578\u5b57\u578b\u5225\u7684\u6578\u7d44\uff0c\u7136\u5f8c\u6211\u5011\u5c07 <span style=\"color: #009900; font-weight: bold;\">[1, 2, 3]<\/span> \u9663\u5217\u8ce6\u503c\u7d66 <span style=\"color: #009900; font-weight: bold;\">numbers<\/span> \u8b8a\u6578\uff0c\u63a5\u8457\u6211\u5011\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">push()<\/span> \u65b9\u6cd5\u5c07 <span style=\"color: #009900; font-weight: bold;\">4<\/span> \u65b0\u589e\u5230 <span style=\"color: #009900; font-weight: bold;\">numbers<\/span> \u6578\u7d44\u4e2d\uff0c\u6700\u5f8c\u6211\u5011\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">console.log()<\/span> \u65b9\u6cd5\u5c07 <span style=\"color: #009900; font-weight: bold;\">numbers<\/span> \u6578\u7d44\u7684\u5167\u5bb9\u8f38\u51fa\u5230\u7d42\u7aef\u6a5f\uff0c\u7d50\u679c\u5c31\u6703\u986f\u793a <span style=\"color: #009900; font-weight: bold;\">[1, 2, 3, 4]<\/span>\u3002<\/p>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cTypeScript \u652f\u63f4\u6578\u7d44(Arrays)\uff0c\u53ef\u4ee5\u4f7f\u7528 <span style=\"color: #009900; font-weight: bold;\">Array<\/span> \u985e\u5225\u4f86\u5efa\u7acb\u6578\u7d44\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u65b9\u6cd5\u4f86\u64cd\u4f5c\u6578\u7d44\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u8f15\u9b06\u5730\u64cd\u4f5c\u8cc7\u6599\u7d50\u69cb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):TypeScript\u4e2d\u7684\u6578\u7d44(Arrays)\u662f\u4e00\u7a2e\u5e38\u898b\u7684\u8cc7\u6599\u7d50\u69cb\uff0c\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u591a\u500b\u503c\uff0c\u4e26\u63d0\u4f9b\u8a31\u591a\u6709\u7528\u7684\u65b9\u6cd5\u4f86\u64cd\u4f5c\u9019\u4e9b\u503c\u3002\u672c\u6587\u5c07\u4ecb\u7d39TypeScript\u4e2d\u6578\u7d44(Arrays)\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u5011\u4f86\u8655\u7406\u8cc7\u6599\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-4856","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-1gk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4856","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=4856"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4856\/revisions"}],"predecessor-version":[{"id":4857,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4856\/revisions\/4857"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}