In node.js, trying to group several messages using underscore, but don't know how to parse it

I am using node.js and redis to receive messages in json, the message in plain test is like this

362S29MM09 36072 36071 ARRIVAL ARRIVAL ON TIME
362S29MM09 36075 36072 DEPARTURE DEPARTURE LATE
362K27MM09 36052 36050 ARRIVAL ARRIVAL ON TIME

Note that the first and second message are the same, so I wish to group these message by the first field, I use the underscore to group the message, but I don't know how to parse the grouped message.

{'type':362S29MM09,'st1':36072 ,'st2':36071 ,'event':ARRIVAL,'next_event':ARRIVAL,'status':LATE}

var groups =  underscore.groupBy(msg, function(obj){ return  obj.train_id}) ;   
console.log(groups);

but it only shows

{ undefined:
   [ { header: [Object], body: [Object] },
     { header: [Object], body: [Object] },
     { header: [Object], body: [Object] } ] }

How can I further parse the message.

I'm not quite sure what your actual question is (you're grouping on train_id which doesn't exist, and where do header and body come from?).

If you want grouping on type, you can use something like this:

var underscore = require('underscore');

var msgs = [ 
{'type':'362S29MM09','st1':36072 ,'st2':36071 ,'event':'ARRIVAL','next_event':'ARRIVAL','status':'ON TIME'},
{'type':'362S29MM09','st1':36075 ,'st2':36072 ,'event':'DEPARTURE','next_event':'DEPARTURE','status':'LATE'},
{'type':'362K27MM09','st1':36052 ,'st2':36050 ,'event':'ARRIVAL','next_event':'ARRIVAL','status':'ON TIME'}
];

var groups = underscore.groupBy(msgs, function(obj){ return obj.type; }) ; 
console.log(groups);

Which results in this output:

{ '362S29MM09': 
   [ { type: '362S29MM09',
       st1: 36072,
       st2: 36071,
       event: 'ARRIVAL',
       next_event: 'ARRIVAL',
       status: 'ON TIME' },
     { type: '362S29MM09',
       st1: 36075,
       st2: 36072,
       event: 'DEPARTURE',
       next_event: 'DEPARTURE',
       status: 'LATE' } ],
  '362K27MM09': 
   [ { type: '362K27MM09',
       st1: 36052,
       st2: 36050,
       event: 'ARRIVAL',
       next_event: 'ARRIVAL',
       status: 'ON TIME' } ] }