Skip to content

Instantly share code, notes, and snippets.

@donavon
Created March 11, 2021 14:02
Show Gist options
  • Save donavon/6a3070d8f94c6b8da19d42571005ef2a to your computer and use it in GitHub Desktop.
Save donavon/6a3070d8f94c6b8da19d42571005ef2a to your computer and use it in GitHub Desktop.
Maps over an array of Github usernames and returns an array of user objects.
const githubUsernames = ['donavon', 'revelcw', '#^%$', 'sessionsfm'];
const fetchGithubUser = async (username) => {
const resp = await fetch(`https://api.github.com/users/${username}`);
return resp.ok ? await resp.json() : null;
}
const users = await Promise.all(
githubUsernames.map(fetchGithubUser)
);
users.forEach((user) => {
console.log(user?.name);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment