I've encountered a problem that has been raised before, and despite trying various solutions such as using .map
or (function(post){ async })(value)
, I'm still unable to move forward...
Here's the scenario: I have an array of objects along with a for loop:
var postsData = [{thumbnail: www.website.com/image.jpg}, {thumbnail: www.website.com/image.jpg}, {thumbnail... etc}];
for (let i = 0; i < 3; i++) {
let thumbnail = postsData[i].thumbnail;
Cloudinary.uploader.upload(thumbnail, function(result){
// Feeling lost here
// The result is returning as an object, and my goal is to update each thumbnail in
// the postsData array to be result.public_id
}, {transformation:[{}]});
} // Loop through all items in the array
// Figure out what to do next with the "updated" postsData array
An illustrative example would greatly aid in grasping the concept, especially since dealing with altering values requires handling asynchronous functions.