我有以下数据
myArray = [ { Tests: [ [Object] ],
_id: '52bd60d72270a398d3f87302',
browser: [ 'FF' ],
id: '71',
mode: 'weekly',
os: 'VM-WIN7-64',
server: '172.16.2.120' },
{ Tests: [ [Object], [Object] ],
_id: '52c247f1cf0060b8cce84b42',
browser: [ 'FF' ],
id: '45',
mode: 'daily',
os: 'VM-WIN7-64',
server: '172.16.2.120' },
{ _id: '52ca2b0dafcec877d925d111',
Tests: [ [Object], [Object], [Object] ],
browser: [ 'FF', 'IE' ],
id: '37',
mode: 'daily',
os: 'VM-WIN7-32',
server: '172.16.2.120' } ];
我只想将这些值推送到newArray,如下所示。怎么可能?我在node.js工作。
newArray = [{
browser: [ 'FF' ],
id: '71'},
{
browser: [ 'FF' ],
id: '45'},
{
browser: [ 'FF', 'IE' ],
id: '37'},
];
答案 0 :(得分:2)
像这样的东西
var newArray = myArray.map(function(obj) {
return {browser : obj.browser, id : obj.id}
});