0

How do I enter successive nulls in a javascript array?

I am having trouble understanding how to enter successive null values in a JS array. This is my working script:

var myApp = angular.module("myApp", []);

myApp.controller("myCtrl", function($scope) {
  $scope.items = [];
  $scope.items[0] = [,,"this doesn't work"];
  $scope.items[0] = [null,"this works"]; 
  $scope.items[1] = [null,,"this works"];
  $scope.items[2] = [null,null,"this doesn't work"];
  $scope.items[3] = [null,,,"this doesn't work"];
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="myApp">
  <div ng-controller="myCtrl">
    <table>
      <tr ng-repeat="row in items">
        <td ng-repeat="column in row">{{column}}</td>
      </tr>
    </table>
  </div>
</body>
Community
  • 1
  • 1
JcoOnline
  • 243
  • 2
  • 13

1 Answers1

1

Problem appears to be with how you are outtputting the values in your angular ng-repeat. Alter the code to use track by to deal with duplicated values.

<tr ng-repeat="tr in items">
    <td ng-repeat="td in tr track by $index">{{td}}</td>
</tr>
epascarello
  • 204,599
  • 20
  • 195
  • 236