[英]Convert Objects to array in angularjs
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. 有任何建议请。
$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);
});
Yao, 姚明,
Look at Lodash or ngLodash. 查看Lodash或ngLodash。 Lodash has lots of function that do exactly what you are looking to do.
Lodash具有很多功能,可以完全满足您的期望。 ngLodash is a fork and AngularJS rewrite of Lodash.
ngLodash是Lodash的fork和AngularJS重写。
https://github.com/rockabox/ng-lodash https://github.com/rockabox/ng-lodash
https://lodash.com https://lodash.com
Hope this helps! 希望这可以帮助!
Regards, Jeff 问候,杰夫
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.