Retrieve standardized array object

1

Hello, everyone. I have a problem retrieving an object, it follows my situation:

How do I do:

$scope.data = [];

for(var i = 0; i < 5; i++) {
    $scope.data.push(i);
}

// Result: [0,1,2,3,4]

Result I need

[[0,1,2,3,4]]

What I need and to assemble a chart with the Charts.js library but the data comes from a query and I am not able to mount this object in this format. (Note: in the project I use angular.js)

Thank you for your attention.

    
asked by anonymous 27.12.2015 / 13:47

1 answer

2

If you need to insert arrays within this $scope.data then when you do $scope.data.push(algo); this algo must be an array.

You can solve this like this:

var _data = [];
for(var i = 0; i < 5; i++) {
    _data.push(i);
}
$scope.data.push(_data);
    
27.12.2015 / 13:50