Compare Arrays for Similar Item

How can I compare 2 arrays to find common items. Say I have and object that is in 2 different arrays and I want to be able to do something with any of the objects that exist in array X and array Y, and ignore any elements that don’t exist in both?

Make a For Each Loop (Array 1)
In the loop:
Make For Each Loop (Array 2) -> Output Element Array 1 = Output Element Array 2 -> return Found

But this will probably kill the performance if the arrays are big, and if the Item at the end of an array is.

Arrays probably support a “find” (in array) function - you could try this too - if existing.

Is this what you mean? How do I use the elements that exist in both?

You add them to a third array.

Yes

Or:

1 Like