Asked 6 years ago
29 Jan 2018
Views 1128
angeo

angeo posted

how to group by object in Javascript ?


var project = [{'name':'p1','manager':'r1'},{'name':'p2','manager':'r2'},{'name':'p3','manager':'r1'} ,{'name':'p4','manager':'r2'} ];


so i want to group by object by manager so it should be group object by manager name

is that any library can help easily at JavaScript ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

use lodash

npm i lodash


i am using electron so i used like this


const lodash=require('lodash'); 
var project = [{'name':'p1','manager':'r1'},{'name':'p2','manager':'r2'},{'name':'p3','manager':'r1'} ,{'name':'p4','manager':'r2'} ];
  var r2groupby = lodash.filter(project , { 'manager': 'r2' } );
console.log(r2groupby);



Post Answer