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