Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the intersection of two arrays by Javascript

Shulou Source: shulou.com Published: 2022-06-01 05:49:57 11月01日 Update

This article mainly introduces Javascript how to achieve the intersection of two arrays, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The intersection of two arrays

To require the intersection of two arrays, first make sure that the array does not repeat, and then use the filter () method and the includes () method.

Var plants1 = ['Saturn',' Earth', 'Uranus',' Mercury', 'Venus',' Earth', 'Mars',' Jupiter']; var plants2 = ['Saturn',' Earth', 'Uranus']; var alonePlants = [. New Set (plants1)] .filter (item = > plants2.includes (item)); console.log (alonePlants) / / ['Saturn',' Earth', 'Uranus'] Thank you for reading this article carefully. I hope the article "how to realize the intersection of two arrays in Javascript" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Array two intersection articles methods values interests at the same time more friends knowledge editing industry information information channels channels references learning help support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Huawei OPPO Reno Shulou Tech Info