I have a problem merging two JSON objects, each from another array, into a new JSON object, in a new Array (the merging has to happen under given conditions).
Example:
First Array:
var array1 = [{box:123,name:xxx,amount:xxx},{box:321,....},...]
var array2 = [{_id:123,look:xxx,title:myBox1},{_id:321,.....},...]
var newArray = [{box:123,name:xxx,amount:xxx,look:xxx,title:myBox1},...]
What I basically need:
Iterate over Array1, iterate over Array2. If box (array1) == _id (array2) merge all attributes from both objects into a new JSON and put it in the first free slot in a new array3.
I hope the example helps to see what I'm trying to do. What is the best solution?
Normally the first attribute in both arrays are also the ones that need to be compared, but it would be could, if the solution would work also if I want to compare e.g. 1st attribute in 1st array with 3rd attribute in 2nd array.
Hope someone can help me out!