简体   繁体   中英

push some json data to empty array in node.js

i have following data

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' } ];

I only want to push some these values to a newArray as follows. How it is possible? I am working in node.js.

newArray = [{    
    browser: [ 'FF' ],
    id: '71'},   
  {     
    browser: [ 'FF' ],
    id: '45'},    
  {   
    browser: [ 'FF', 'IE' ],
    id: '37'},
   ];

Something like this

var newArray = myArray.map(function(obj) {
    return {browser : obj.browser, id : obj.id}
});

FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM