how to return value of the FetchAPI request inside a variable?

0

I need to return a value of a request made with Javascript FetchAPI for a variable, I made that attempt but without success:

function listeItens(tipo_item)
    {
        var itens;
        fetch('ajax/html/liste_itens.asp?tipo_item='+tipo_item)
            .then(response =>response.text())
            .then((data)=>{
                itens = data;
                console.log(itens); // AQUI LISTA NORMALMENTE O RETORNO
            })
            .catch(err => console.log(err));                    
        console.log(itens); // AQUI LISTA undefined
        return itens;    
    }

I wonder if there's a way to do this?

    
asked by anonymous 06.06.2018 / 17:28

0 answers