By visiting all the keys for each element in the source you are making an algorithm of O(nm). Also if the arrays are long enough it will miss the CPU cache for each source item. Its an efficient way basically.
An alternative is to consume more memory and keep the unique elements in a map and going trough the source only once. This way the checks are O(1).
If the elements are objects the memory overhead will be small as you store references.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.