I have a problem with array variable scope in Javascript. Here's my code
var features = new Array();
var x = 0;
$.ajax({
async: true,
url: domain + "client/applications/getFeatures",
dataType: 'json',
success: function(data) {
if (data.code == 200) {
$.each(data.data, function(i, val) {
features[x] = val.features_value;
x++;
});
}
}
});
alert(features[0]);
The result of the pop up always "undefine". Do you have solutions ? Thank you