Simple question I hope (not sure what I am missing);
How can I push items to a basic and not an indexed array?
When doing this:
var shops = [];
angular.forEach(data, function(value, index) { //loop over data
shops.push(value.SHOP_CODE);
});
When you are logging the shops array to console, the array is probably empty and hence it says Array[0].
The contents of the array are evaluated again when you click the dropdown arrow beside Array[0]. So at the time of your click on the dropdown the array is not empty and hence showing 4 elements.
If the array were not empty at the point where you do console.log(shops), then you would get the result you are looking for.
I suggest you add a breakpoint at the statement console.log(shops) and check the contents of the array.
Thanks to @Patrick Evans and @SLePort, I realized I needed to wait for the promise. This works:
.$promise.then(function(data) {
$scope.workOrder = data;
angular.forEach(data, function(value, index) { //loop over aircraft data
shops.push(value.SHOP_CODE);
});
shops.sort();
console.log(shops);
});
Array[0]as it had no length at the time. But when you went to go look at it in the console it had filled. The initial line for a logged array does not update when the array updates