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

137
Visualizações
Is it possible to set the value of promise to a object

So I have used .then to try and assign the value of promise to the object but I can't and now I tried a anonymous async function which isnt helping me.

import fetch from 'node-fetch'
import { setProps } from '../helpers/objectResponse.js';
if (!globalThis.fetch) {
    globalThis.fetch = fetch;
}

const wrapMe = (pokimon) => {
    let value;
    const getPokimon = async (pokimon) => {
    const data = await fetch(`https://pokeapi.co/api/v2/pokemon/${pokimon.toLowerCase()}`);
    const response = await data.json();
    return response
    }

    (async () => {
        const data = await getPokimon(pokimon);
        return value = data
    })
    return value

}```
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

the wrapMe me function need to be async

about 4 years ago · Juan Pablo Isaza Relatório

0

you must have to use callback or promise for ajax requests you cant simply call ajax and get its value for return

Return data.json() without using await so your promise will be returned to getPokimon

try doing this way

function getPokimon(pokimon) {
    return fetch(`https://pokeapi.co/api/v2/pokemon/${pokimon.toLowerCase()}`).then(r=>r.json())
}

getPokimon("ditto").then(r=>{
    console.log(r)
})

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