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

107
Visualizações
Accessing object data inside a promise

So I have a getBlockByHeight method which is as follows.

getBlockByHeight(height) {
    let self = this;
    return new Promise((resolve, reject) => {
        try{
            let block = self.chain.filter(p => p.height === height)[0];
            if(block){
                resolve(block);
            } else {
                resolve(null);
            }
        } catch (err) {
        reject(new Error(err));
    }
    });
}

I then want to validate my blocks in another method and am trying to do the following.

let previousBlock = self.getBlockByHeight(block.height -1);

That line returns a promise with my block object in it correctly. If I console.log previousBlock it prints as follows.

Promise {
  Block {
    hash: '5535a9bf09a3667a533df8f8a90a6ae8e8dfe1ca9f3d5305df5a1d593d2afcf6',
    height: 1,
    body: 'longHexString',
    time: '1633881202',
    previousBlockHash: '1f018de4cb50fe2fc57b43c1a4972fde53d7e4ab9ca5809784d49e5a57497312'
  }
}

My question is how do I access the hash in this previousBlock object. if I try

let preBlockHash = previousBlock.hash

I get undefined. I'm not really sure why this is happening so any help would be appreciated thanks.

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