Recover standardized array object

Asked

Viewed 43 times

1

Hello, everyone. I have a problem to recover an object, follow my situation:

Like I’m doing:

$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 is to compile a chart with the Charts.js library but the data comes from a query and I am not able to assemble this object in this format. (Note: I do not use angular.js)

Thank you for your attention

  • Test like this: https://jsfiddle.net/y9p0xbu4/, that’s what you need?

1 answer

2


If what you need is to insert arrays inside that $scope.data then when you do $scope.data.push(algo); that algo has to be an array.

You can fix it like this:

var _data = [];
for(var i = 0; i < 5; i++) {
    _data.push(i);
}
$scope.data.push(_data);
  • 1

    Look just... guy was that same gave right here. thank you very much friend!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.