JSON object reorganization

  node.js, question

The first is:

[
 bracket
 name: 'name1',
 cag: 'a'
 },
 bracket
 name: 'name2',
 cag: 'a'
 },
 bracket
 name: 'name3',
 cag: 'a'
 },
 bracket
 name: 'name4',
 cag: 'b'
 },
 bracket

The second is:

bracket
 a: [
 bracket
 name: 'name1',
 cag: 'a'
 },
 bracket
 name: 'name2',
 cag: 'a'
 },
 bracket
 name: 'name3',
 cag: 'a'
 bracket
 ],
 b: [
 bracket
 name: 'name4',
 cag: 'b'
 bracket
 bracket
 bracket

How does JS reorganize the first format into the second format?

var o = {} , item = {};  // list is your array
 for(var i=0,len=list.length;  i<len;  I plus)
 item = list[i];
 o[item.cag] || (o[item.cag] = []);
 o[item.cag].push(item);
 bracket

https://jsfiddle.net/chexian/y3mcuga4/