Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
array value not showing length, but when i open so the element is exist

array value not showing length, but when i open so the element is exist. but length and some other functions of array not working... """const getingLikedNft = async () => { setMyNftLoading(true); const res = await axios.get(${BACKEND_URL}views_and_likes); console.log("resshan", res); // let likedNft = []; var myLikedNft = new Array();

res?.data.forEach((element) => {
  // console.log("xshan", element);
  if (element?.likedAccounts.length > 0) {
    element?.likedAccounts.forEach(async (elem) => {
      if (elem?.toLowerCase() == user?.address?.toLowerCase()) {
        console.log("resshan_elem", element);
        try {
          let res = await axios.post(`${BACKEND_URL}single-nft`, {
            tokenId: element.tokenId,
            tokenAddr: element.tokenAddr,
          });
          console.log("reslikedNFT", res.data);
          // const uri = await contracts?.closedSeaNft?.methods
          //   .tokenURI(element.tokenId)
          //   .call();
          // const res = await axios.get(uri);
          var nftData = {
            description: res?.data?.metadata?.description,
            image: res?.data?.metadata?.imageUrl,
            title: res?.data?.metadata?.name,
            url: `/asset/${res?.data?.tokenAddr}/${res?.data?.tokenId}`,
          };
          console.log("reslikedN22FT2324232", Array.prototype.nftData);
          myLikedNft = [...myLikedNft, nftData];
          // myLikedNft.push({
          //   description: nftData.description,
          //   image: nftData.imageUrl,
          //   title: nftData.name,
          //   url: `/asset/${res?.data?.tokenAddr}/${res?.data?.tokenId}`,
          // });
        } catch (err) {
          console.log("element?.likedAccounts [err]", err);
        }
        // likedNft.push(element);
        // console.log("elem", elem);
      }
    });
  }
});
console.log("reslikedNFT2321312341312dasd", myLikedNft);
setMyLikesCollection(myLikedNft);
setTimeout(() => {
  setMyNftLoading(false);
}, 2000);

};"""

you can see it is showing empty array. enter image description here

but when i open this so the element is exists.

enter image description here

how can i solve this kindly help...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are making an async call for every iteration in the forEach loop. But the execution of the forEach will finish before you get a response for each of your async calls.

When you print the myLikedNft to the console, at the time of printing, the array has no data, because the async calls have not resolved. But when you expand them in the console, it gives you the latest value of the expression.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda