I am trying to grab the concept of destructing properly. I understand that it is a way of assigning values to a variable from an object or array. I have a data fetched from an API this way
const getAUserProfile = () => {
const api = "https://randomuser.me/api/";
const data = fetch(api).then(response => {
return response.json();
});
console.log(data);
displayUserPhotoAndName(data);
};
the console.log result shows this
In the displayUserPhotoAndName function, I am attempting to destructure the data like this
const displayUserPhotoAndName = data => {
const {results} = data;
console.log(results);
};
But console.log(results)
returns undefined. Apparently I seem not to be destructuring the data properly or my fetch method is not correct, these are my thoughts. Please what would be the right way to destructure data in this case?