lol. I literally googled the same thing earlier today. Mine was a little more complicated though, I had to search through nested objects/arrays. I guess the most efficient way depends on the language (if for loops are faster than a while loop etc.) but unless the array size is large (thousands of entries) then I'd say it doesn't make too much difference.
If you can order either A or B then you could section the array up or something which would make looping the numbers of entries smaller.