I have a question strictly based in regards to performance while iterating through two different arrays.
My first array is composed in the following way, objects consisting of an {id, number}
var arr1 = [{id: 1, number: 7}, {id: 2, number: 5}];
My second array is composed of the same id field, and a string value
var arr2 = [{id: 2, string: 'foo'}, {id: 1, string: 'bar'}];
My question is this, I need to match the id's from the first array with the second array specifically in that order. I wrote my code in the following manner.
arr1.forEach(function(x){
arr2.forEach(function(y){
if(condition){
Do something...
}
});
});
Is there a faster/more effective way to iterate through the arrays without two forEach loops? Or is that configuration the best method for comparing all the values?
The code I wrote works and returns no problem, but I can't help thinking there's a faster (performance wise) method or means of doing the same thing here...
Thanks for any and all insight in regards to this!