I want to transfer the images selected by the user to an object with javascript and read from there. I do this using the code below. When I print the productImages variable to the console, the data appears, but what should I do to read the data one by one?
let productImages = {};
var totalfiles = document.getElementById('uploadImages').files.length;
let x = 0;
for (var index = 0; index < totalfiles; index++) {
var file = document.getElementById('uploadImages').files[index];
if (file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = async function(e) {
Image = e.target.result;
productImages[x] = {'data': {'image': Image}};
x++;
};
}
}