Well, here are some javascript basic issues.
Your albums remains unchanged because your definitions: video.width = element.width and video.height = element.height remain scoped inside forEach function which can’t mutate array.
About Array.prototype.forEach():
- it does not mutate the array on which it is called.
- it always returns the value
undefined
So, to solve your problem, replace forEach with map and return the modified video object.
Replace:
albums.media.forEach((video) => {
With
albums.media = albums.media.map((video) => {
Replace:
});
return albums;
With:
return video; //return the modified video inside .map function
});
return albums;