0

I have a function that has asynchronous tasks in it

function getDroplets(key) {
    return getRequest('https://api.digitalocean.com/v2/droplets', key).then(function(response) {
        var droplets = response.droplets;
        var numDroplets = droplets.length;
        return {
            data: response,
            droplets: droplets,
            numDroplets: numDroplets
        }
    });
}

I want to take the return data from this function and store it in a variable named dropletData. But, I currently am getting undefined.

var dropletData = async(key) => {
    data = await getDroplets(key);
    return data;
};

dropletData = dropletData(api_key);
Jordan Baron
  • 3,752
  • 4
  • 15
  • 26

0 Answers0