title: Merging two JSON Objects under condition for two JSON Arrays
body: <p>I have a problem merging two JSON objects, each from another array, into a new JSON object, in a new Array (the <strong>merging</strong> has to happen under given conditions).</p>
  
  <p>Example:</p>
  
  <p>First Array:</p>
  
  <pre><code>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},...]
  </code></pre>
  
  <p><strong>What I basically need:</strong>
  Iterate over Array1, iterate over Array2. If box <code>(array1) == _id (array2)</code> merge all attributes from both objects into a new JSON and put it in the first free slot in a new array3.</p>
  
  <p>I hope the example helps to see what I'm trying to do. What is the best solution? </p>
  
  <p>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.</p>
  
  <p>Hope someone can help me out!</p>