I want to access variable "gender" in function(data) and then display in an alert outside function(data).
var gender = "";
fetch('https://randomuser.me/api/?results=10')
.then(function(response) { return response.json(); })
.then(function(data) {
//console.log(data.results[0].gender);
gender = data.results[0].gender;
})
.catch(function(error) {
console.log(error);
});
alert(gender);