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

100
Visualizações
async function not returning value

I am trying to return buildings and access it in the promise at the bottom of the script, but it seems like the console.log in the then part of the promise is executing before the getRecord function finishes, and so I can't access the array I am creating.

async function getRecords() {
     const buildings =[]
     data =updateTable.select({
        fields:['building_name']
    }).eachPage(function page(records, fetchNextPage){
        
        records.forEach(function(record){
            num++
            //console.log(num)
            try{
             //console.log(record['fields']['building_name'])
             
             buildings.push(record['fields']['building_name'])
            }
            catch(err){
                console.log('hello1')
                console.log(err)
            }

        }) 
            try{
        fetchNextPage()
            }
            
            catch{
                console.log('hello2')
                return buildings;
            }
    },function (err) {
        console.log(err)
        console.log('hello3')
        if (err) {
            console.log('errror')
            console.log(err);
            return;
        }
        console.log('hello4')
        console.log(buildings)
        console.log('hello5')
        return buildings
           
    });   console.log('hello6')
    }




getRecords().then(function(r){
    console.log('test')
    console.log(r)
})
about 4 years ago · Juan Pablo Isaza
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