I am trying to set an email address as a variable to use later. The email, as well as other profile information, is stored in a JSON file. Here is my JavaScript code:
var email = "missing";
$.getJSON("/api/v1/users/USERID/profile", function(profiledata) {
var email = profiledata.primary_email;
});
console.log(email);
The result written to the console is "missing". I want the result to be the user's email.
However, if I were to do
$.getJSON("/api/v1/users/USERID/profile", function(profiledata) {
console.log(profiledata.primary_email);
});
It will correctly output the email address value, but only to the console. How would I go about storing the email address as a variable for use later on?