1

I want to get each file's name from firebase storage and put in map array, so I got this code.

listRef.listAll().then((res) => {
    res.items.forEach((itemRef) => { 
      //console.log(itemRef);
      
      itemRef.getMetadata().then((metadata) => {

        itemName = metadata.name;
        map.set(i,itemName);
        i++;
      
      }).catch((error) => {
        console.log(error);
      });

    });

  }).catch((error) => {
    console.log(error);
  });

  console.log(map); //it shows Map(0) but have entries in it
  map.forEach((value,key) => {
    console.log("123") //nothing happened
});

I successfully got names all in the map, but it shows Map(0) and have those names in its entries... so I can't get anything in forEach cycle, do anyone know why does it occur and how to solve it?

kittenBark
  • 21
  • 4
  • 1
    to answer the `it shows Map(0) but have entries in it` ... when you log an Object to the console and inspect it, the console shows the current state of the Object, not the state when it was logged - due to the asynchronous nature of the data being added to the Object, this can get confusing – Bravo Aug 13 '21 at 03:16

0 Answers0