I have angular js application. where I am trying to parse a json array using angular.forEach. It is showing strange behavior.
When I am trying to console this it is showing data but when I trying to console with length it is showing length as 0.
I want output outside the loop only. How can I achieve this ?
Can anyone help me on this ?
function loadRelease() {
$scope.datas.releaseData = [];
angular.forEach($scope.datas.repositoryData, function(value, key) {
GitHubService.getDevMasterReleaseDate(value.url)
.then(function(responseRepo) {
var dataToOperate = [];
var dataJson = {
'repoName': value.name
, 'masterArray': []
, 'devArray': []
}
angular.forEach(responseRepo.data, function(value, key) {
if (value.target_commitish == 'master') {
dataJson.masterArray.push(value);
} else {
dataJson.devArray.push(value);
}
});
$scope.datas.releaseData.push(dataJson);
}, function(error) {
});
});
console.log($scope.datas.releaseData);
console.log('length :: ' + $scope.datas.releaseData.length);
}
Console:

then