// for use with callbacks... import { forEachOf } from "async-es"; const images = {cat: "/cat.png", dog: "/dog.png", duck: "/duck.png"}; const sizes = {}; forEachOf(images, (value, key, callback) => { const imageElem = new Image(); imageElem.src = value; imageElem.addEventListener("load", () => { sizes[key] = { width: imageElem.naturalWidth, height: imageElem.naturalHeight, }; callback(); }); imageElem.addEventListener("error", (e) => { callback(e); }); }, err => { if (err) console.error(err.message); // `sizes` is now a map of image sizes doSomethingWith(sizes); });