I have an Javascript object that looks like this:
const obj = [
{
name: "Ali",
userID: 123,
type: "photo",
photo: {
"title": "Me",
"src": "/cool.jpg",
}
},
{
name: "Ali",
userID: 123,
type: "photo",
photo: {
"title": "Photo",
"src": "/photo.jpg"
}
},
{
name: "John",
userID: 1234,
type: "photo",
photo: {
"title": "Photo",
"src": "/photo.jpg"
}
},
{
name: "John",
userID: 1234,
type: "photo",
photo: {
"title": "Photo",
"src": "/photo.jpg"
}
}];
I need to loop over it and return an array that will look like:
const obj = [
{
name: "Ali",
userID: 123,
type: "photo",
photos: [
{
title: "Me",
src: "/cool.jpg"
},
{
title: "Photo",
src: "/photo.jpg"
}
]
},
{
name: "John",
userID: 1234,
type: "photo",
photos: [
{
"title": "Me",
"src": "photo.jpg"
},
{
title: "Photo",
src: "/photo.jpg"
}
]
}
]
Note that the first object can contain an object with the same name over 100 times, I need it only once and inside an array of all of his photos.. How would I do that? What type of loop should i use? Thanks...
photoof a user into multiplephotos(which can be excerpt from here). What have you tried? You question as it stands shows no effort from your side. Do you have any code you already tried with a specific issue? Or you're trying to find someone to code this for you?obj?