I am learning JavaScript and AngularJS. I want to use the values that are outside of function, but I don't know how to access them.
Here is my code (AngularJS Controller):
var init = function() {
    $http.get('getSomeValues').then(function (res) {
        var returnArray = res.data; // Result is array
        for(var i=0; i < returnArray.length; i++) { // Loop through the array
            console.log("THIS WORKS FINE: ", returnArray[i].value); // It works
            $http.get('getOtherValues/' + returnArray[i].value).then(function (res) {
                console.log("WHAT'S IN IT: ", returnArray[i].value); // Shows 'undefined' error
            });
        }
    });
};
init();
So basically I want to access the array returnArray, but I can't. Is there any good way to access the values? I assume that '.then(function ..' causes error..
 
    