I have a function that returns an array of Objects (Wordpress posts, in this case). I want to loop through that array, use the ID from each of the Post Objects, and spit out a new array that includes the Post Thumbnail image (which is gotten with another function get_the_post_thumbnail(‘ID’)).
The most efficient way to do this would be to use the Array.map() method. This method allows you to iterate over an array and modify each item in the array. For example, given the array from above, you could do something like this:
let newArray = array.map((postObj) => {
let newObj = {
...postObj,
the_image: get_the_post_thumbnail(postObj.ID)
}
return newObj;
});
This would loop through the original array and create a new object that includes the image url for each post.
I don’t think that will work… The array I’m starting with is more than just the array of IDs… It’s an array of objects, and I need to use a specific key (‘ID’) from each object as the argument for get_the_post_thumnbail_url($ID)