getData = () => {
var id;
$.getJSON('url', function(data) {
id = data['id']
});
return id
}
I am trying to fetch data from a url and save the id from the data as a seperate variable. However, the variable id seems to appear undefined even after being set as data['id']. Is there anything I can do to fix this?