title: Javascript array of objects with subarray creation
body: <p>I am working on a javascript program and I need an object to return to the frontend.</p>
  
  <p>I wrote some queries that return:</p>
  
  <ul>
  <li>photos: array of {id, owner, link, description, name}</li>
  <li>comments: array of {id, text, photoTarget, userOrigin, name } //photoTraget is the photo id</li>
  </ul>
  
  <p>I want to create a new array called photoArray, which has the comments for each photo stored as a subarray.</p>
  
  <p>This is the structure : </p>
  
  <pre><code>photoArray[0] ={
          id, 
          owner, 
          link, 
          description, 
          name, 
          comment: [id, text, photoTarget, userOrigin, name]
        }
  </code></pre>
  
  <p>approach: </p>
  
  <pre><code>for(var i=0; i&lt; photos.length; i++){
     for(var j=0; j&lt; comments.length; j++){
        if(photos[i].id == comments[j].photoTarget){
  
                //I can't get this part to work
  
         }
     }
  }
  </code></pre>