I have a list of numbers that I need to convert into a two-dimensional array. For example:
let data=['1','4','2','1','6','9','1','5',]
The desired output would be:
result = [['1','4','2','1'],['6','9','1','5']]
My ultimate goal is to create a dynamic grid-style menu system in Ionic using the following example:
<div class="text-center" ng-init="models = [['12','1','2','3','3'],['4','4','5','6','7']]">
<div ng-repeat="m in models">
<span class="control-label1" ng-repeat="movie in m track by $index">
{{movie}}</span>
</div>
</div>
To achieve this, I need to populate my array with unique values like so:
// Function to add a unique value to the array
$scope.addhourinArray = function (value) {
if (value) {
if ($scope.hourArray.indexOf(value) == -1) {
$scope.hourArray.push(value);
}
}
};
// Adding values to the two-dimensional array
for (var i = 0; i < data.length; i++) {
$scope.addhourinArray(hour);
}