Reputation: 583
I have this data:
$scope.data = [
{
data1:"1",
data2:"2"
},
{
data1:"1",
data2:"2"
}
];
I want to output them in console log as:
[ [1,2], [1,2] ]
Any suggestions please.
Upvotes: 0
Views: 53
Reputation: 17430
$scope.data = [{
data1:"1",
data2:"2"
}, {
data1:"1",
data2:"2"
}].map(function (o) {
return [o.data1, o.data2];
// or, if you really need the items to be numbers:
// return [o.data1, o.data2].map(Number);
});
Upvotes: 1
Reputation: 964
Yao,
Look at Lodash or ngLodash. Lodash has lots of function that do exactly what you are looking to do. ngLodash is a fork and AngularJS rewrite of Lodash.
https://github.com/rockabox/ng-lodash
Hope this helps!
Regards, Jeff
Upvotes: 0