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

129
Visualizações
Array is looking empty, but have 4 objects

I make a async function to get offers, and add to array with another array. But the offers array are looking empty in console, but when I click shows the itens.

The products are comming that's isn't the problem. The problem is that I can't add the arrayOffers to itemsArray.

OBS: the forEach is from p-interation lib.

this is my code.

useEffect(() => {
        if (auth && auth._id) {
            const fetchUserVisitedProducts = async (id) => {
                const user = await getPublicUserRequest(id);
                let array = [];

                forEach(user.offers_visited, async (id) => {
                    const offers = await getOfferRequest(id)
                    array.push(offers)
                });
                const arrayOffers = array;
                console.log(arrayOffers)
                const itemsArray = [ ...user.barbadas_visited, ...arrayOffers]
                console.log(itemsArray)
                
            }    
            fetchUserVisitedProducts(auth._id)
        }
  
    },[auth])

In the image, I see one array with 4 objects, but looks empty. And another array that is correct.

IMAGE ARRAYS

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

0

Try replacing the

 forEach(user.offers_visited, async (id) => {
    const offers = await getOfferRequest(id)
    array.push(offers)
 });

with

  for (const id of user.offers_visited) {
    const offers = await getOfferRequest(id)
    array.push(offers)
  }

as forEach is not meant to be used with async.

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