Find common items from two Arrays in JavaScript

In this tutorial, you will learn how to find common items from two arrays in JavaScript.

How to find if two arrays contain any common item in Javascript, find common elements only between 2 arrays, Get common elements in two arrays, Find common elements in a list of arrays, Comparison of Two arrays Using JavaScript, Get common elements from two Arrays.

There are many ways to find common items from two arrays. But we explain here one of them using for loop.

Follow the steps below to find common items from two arrays

  1. First, initialize a new empty array.
  2. Now, iterate all the items in one of them array using for loop.
  3. In this for loop, iterate all the items of the other array.
  4. If the item is present, then add to the new array.
  5. Otherwise continue with the new item.

By following the above steps, we will create a function that returns the common items from two arrays.

Method 2: Using forEach

Let’s use the forEach method to get the common items from two arrays.

That’s it for today.
Thank you for reading. Happy Coding!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *