I am currently learning JavaScript and I have come across the Object.assign() method but I am not quite sure how to apply it in project.
Here are my examples :
This is the reference array that each new profiles array should parse
const references = {
"photos": {
"paul": {
"version": {
"amsterdam": {
"image_url": "firstUrl",
},
"rotterdam": {
"image_url": "secondUrl",
}
}
},
"mary": {
"version": {
"berlin": {
"image_url": "thirdUrl",
}
}
},
"vincent": {
"version": {
"london": {
"image_url": "fourthUrl",
},
"paris": {
"image_url": "fifthUrl",
},
"prague": {
"image_url": "sixthUrl",
}
}
}
}
}
This is what my API request spits out
const profiles = {
"paul": "rotterdam",
"vincent": "prague"
}
What I'd like to achieve is put the according image_url for each version of the photo like this
newArray = {
"paul": "secondUrl",
"vincent": "sixthUrl"
}
But is it even possible ? Or is it not the purpose of Object.assign()?
Thank you very much!
Object.assingn()allow you to copy without reference an object in another, it doesn't fit your need here.