It seems like your code is correct, the issue you are facing might be related to another aspect of your AngularJS application. Please check the console for any errors and provide additional information in your question.
The loop adds elements to the array $scope.B
and displays them in the view using the json
filter.
Code snippet:
angular
.module('App', [])
.controller('DefaultController', ['$scope', function ($scope) {
$scope.B = [];
angular.forEach([0, 1, 2, 3], function (value, index) {
$scope.B.push(value);
});
}]);
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.10/angular.min.js"></script>
<div ng-app="App">
<div class="container" ng-controller="DefaultController">
{{ B | json }}
</div>
</div>