{"id":5687,"date":"2025-06-01T13:49:46","date_gmt":"2025-06-04T06:16:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5687"},"modified":"2025-06-04T13:49:46","modified_gmt":"2025-06-04T06:16:46","slug":"%e4%ba%86%e8%a7%a3reactlist%e7%9a%84%e4%ba%a4%e9%9b%86intersection%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/react-js\/%e4%ba%86%e8%a7%a3reactlist%e7%9a%84%e4%ba%a4%e9%9b%86intersection%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u638c\u63e1 React.JS\uff1a\u8f15\u9b06\u8655\u7406 List \u7684\u4ea4\u96c6\u529f\u80fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"React, React List, Intersection, JavaScript, \u524d\u7aef\u958b\u767c, \u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\"><\/p>\n<h1>\u638c\u63e1 React.JS\uff1a\u8f15\u9b06\u8655\u7406 List \u7684\u4ea4\u96c6\u529f\u80fd<\/h1>\n<p>\u5728\u73fe\u4ee3\u524d\u7aef\u958b\u767c\u4e2d\uff0cReact.JS \u662f\u4e00\u500b\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\uff0c\u5b83\u8b93\u958b\u767c\u8005\u80fd\u5920\u9ad8\u6548\u5730\u69cb\u5efa\u7528\u6236\u754c\u9762\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5229\u7528 React.JS \u4f86\u8f15\u9b06\u8655\u7406 List \u7684\u4ea4\u96c6\uff08intersection\uff09\uff0c\u5e6b\u52a9\u4f60\u63d0\u5347\u958b\u767c\u6548\u7387\u3002<\/p>\n<p>List \u7684\u4ea4\u96c6\uff08intersection\uff09\u662f\u6307\u5169\u500b\u6216\u591a\u500b List \u4e2d\u76f8\u540c\u7684\u5143\u7d20\u3002\u8b93\u6211\u5011\u901a\u904e\u4e00\u500b\u7c21\u55ae\u7684\u4f8b\u5b50\u4f86\u7406\u89e3\u9019\u4e00\u6982\u5ff5\uff1a<\/p>\n<pre class=\"brush: python\">\nconst list1 = [1, 2, 3, 4, 5];\nconst list2 = [3, 4, 5, 6, 7];\n<\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u5169\u500b List \u7684\u4ea4\u96c6\u70ba <span style=\"color: #009900; font-weight: bold;\">[3, 4, 5]<\/span>\u3002<\/p>\n<p>### \u4f7f\u7528 React.JS \u5be6\u73fe List \u7684\u4ea4\u96c6<\/p>\n<p>\u5728 React.JS \u4e2d\uff0c\u8a08\u7b97 List \u7684\u4ea4\u96c6\u76f8\u7576\u7c21\u55ae\u3002\u6211\u5011\u53ef\u4ee5\u5b9a\u7fa9\u4e00\u500b\u51fd\u6578\uff0c\u63a5\u6536\u5169\u500b List \u4f5c\u70ba\u53c3\u6578\uff0c\u4e26\u8fd4\u56de\u5b83\u5011\u7684\u4ea4\u96c6\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u7684\u5be6\u73fe\u65b9\u5f0f\uff1a<\/p>\n<pre class=\"brush: python\">\nconst intersection = (list1, list2) => {\n  return list1.filter(element => list2.includes(element));\n};\n<\/pre>\n<p>\u63a5\u8457\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u9019\u500b\u51fd\u6578\u4f86\u8a08\u7b97 List \u7684\u4ea4\u96c6\uff1a<\/p>\n<pre class=\"brush: python\">\nconst list1 = [1, 2, 3, 4, 5];\nconst list2 = [3, 4, 5, 6, 7];\n\nconst intersectionResult = intersection(list1, list2);\n\nconsole.log(intersectionResult); \/\/ [3, 4, 5]\n<\/pre>\n<p>### \u5728 React \u4e2d\u6e32\u67d3 List \u7684\u4ea4\u96c6<\/p>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u4f86\u770b\u770b\u5982\u4f55\u5728 React \u4e2d\u6e32\u67d3\u9019\u500b\u4ea4\u96c6\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684 React \u61c9\u7528\u793a\u4f8b\uff1a<\/p>\n<pre class=\"brush: python\">\nconst App = () => {\n  const list1 = [1, 2, 3, 4, 5];\n  const list2 = [3, 4, 5, 6, 7];\n  const intersectionResult = intersection(list1, list2);\n\n  return (\n    <div>\n      <h2>List 1:<\/h2>\n      <ul>\n        {list1.map(item => (\n          <li key={item}>{item}<\/li>\n        ))}\n      <\/ul>\n      <h2>List 2:<\/h2>\n      <ul>\n        {list2.map(item => (\n          <li key={item}>{item}<\/li>\n        ))}\n      <\/ul>\n      <h2>Intersection:<\/h2>\n      <ul>\n        {intersectionResult.map(item => (\n          <li key={item}>{item}<\/li>\n        ))}\n      <\/ul>\n    <\/div>\n  );\n};\n<\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86 React.JS \u7684 `filter()` \u65b9\u6cd5\u4f86\u8a08\u7b97 List \u7684\u4ea4\u96c6\uff0c\u4e26\u5229\u7528 `map()` \u65b9\u6cd5\u4f86\u6e32\u67d3\u7d50\u679c\u3002<\/p>\n<p>### \u7d50\u8ad6<\/p>\n<p>\u7e3d\u4e4b\uff0c\u5229\u7528 React.JS \u8655\u7406 List \u7684\u4ea4\u96c6\u529f\u80fd\u4e0d\u50c5\u7c21\u55ae\uff0c\u800c\u4e14\u9ad8\u6548\u3002\u9019\u7a2e\u65b9\u6cd5\u8b93\u958b\u767c\u8005\u80fd\u5920\u8f15\u9b06\u5730\u5728\u7db2\u9801\u61c9\u7528\u7a0b\u5f0f\u4e2d\u5be6\u73fe\u8907\u96dc\u7684\u6578\u64da\u8655\u7406\u908f\u8f2f\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\u900f\u904e\u672c\u6587\u7684\u4ecb\u7d39\uff0c\u5e0c\u671b\u4f60\u80fd\u5728\u5be6\u969b\u958b\u767c\u4e2d\u9748\u6d3b\u904b\u7528\u9019\u4e00\u6280\u5de7\uff0c\u63d0\u5347\u4f60\u7684\u524d\u7aef\u958b\u767c\u6280\u80fd\uff01<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u4e86\u89e3ReactList\u7684\u4ea4\u96c6(Intersection)\u529f\u80fd\uff0c\u53ef\u4ee5\u8b93\u4f60\u66f4\u6709\u6548\u7387\u5730\u6bd4\u8f03\u5169\u500bList\uff0c\u4e26\u627e\u51fa\u5169\u8005\u7684\u5171\u540c\u9805\u76ee\uff0c\u4ee5\u53ca\u66f4\u6df1\u5165\u5730\u4e86\u89e3ReactList\u7684\u529f\u80fd\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":[184,183],"tags":[182,181],"class_list":["post-5687","post","type-post","status-publish","format-standard","hentry","category-react","category-react-js","tag-react","tag-react-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1tJ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5687","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=5687"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5687\/revisions"}],"predecessor-version":[{"id":5688,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5687\/revisions\/5688"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}