Kevin Powell - CommunityKP-C
Kevin Powell - Communityβ€’3y agoβ€’
8 replies
Matt

Working with Sample API

let api = "https://randomuser.me/api/";

function fetchData() {
    fetch(api)
    .then(response => response.json())
    .then(data => {
        console.log(data);
    })
}

fetchData();


I'm workig with a sample RandomUser API. When running this code, it returns this object (see img #1). I'm attempting to retreive the data within 'results'. Creating a variable like let result = data.result returns (see img #2). But, when I try to log the gender, but calling console.log(result.gender), I get undefined.

How do I properly access the results data?
image.png
image.png
Was this page helpful?