I have very basic async function going on here. my primary function "formatData"
is formatting some data from an array "users"
. which are basically some github usernames.
This function formats the data in this way :
[
{ name: 'rocktimsaikia', followers: 12 },
{ name: 'aholachek', followers: 90 },
{ name: 'benawad', followers: 30 }
]
Very basic . But the issue is to get the followers count
i created another async
function "getFollowers"
which extracts the followers count with given argument which is the github user name
that i am providing in formatData
.
Here is my code :
const getFollowers = async name => {
const data = await fetch(`https://api.github.com/users/${name}`);
const { followers } = await data.json();
return followers;
};
const formatData= async () => {
const users = ["rocktimsaikia", "aholachek", "benawad"];
const result = await users.map(async (user) => ({
name: user,
followers: await getFollowers(user)
}));
return result;
};
But the function formatData()
returns everything with a promise. What am i missing here ? please help !