getBase64 inside a loop

Viewed 32

I try to use getBase64 (to convert images to base64) inside a loop. The thing is that the front print the same image all the times.

const cloneResponse = JSON.parse(JSON.stringify(previewDataResponse));

async function filesToBase64() {
      if (imageUpdate.length > 0) {
        console.log(imageUpdate);
        cloneResponse.response_json_new.finalResponse.image = await getBase64(imageUpdate[0]);
      }
      if(lateralImages.length > 0){
        for (let i of cloneResponse.response_json_new.lateral.item_lateral){ 
              for (let j of lateralImages){
          let my64 = j;             
          i.image_lateral[0].path_image_lateral = await getBase64(my64);
        }
        }
      }
    }

const lateralImages is an array of objects with this structure:

[{name: 'IMG_20211015_151052.jpg', lastModified: 1663252467419, lastModifiedDate: Thu Sep 15 2022 16:34:27 GMT+0200 (hora de verano de Europa central), webkitRelativePath: '', size: 4178792}, {name: 'steps.jpg', lastModified: 1663236412688, lastModifiedDate: Thu Sep 15 2022 12:06:52 GMT+0200 (hora de verano de Europa central}]

Thanks for your help

1 Answers

At the end i change the code and did this:

for (let i of cloneResponse.response_json_new.lateral.item_lateral){            
            const image_to_base64 = lateralImages.find(file => file.name === i.image_lateral[0].path_image_lateral);
            i.image_lateral[0].path_image_lateral = await getBase64(image_to_base64);          
        }
Related