Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

lodash group by except group null items

let objects = [
  {office: null},
  {office: {name: 'My Office 1'}},
  {office: {name: 'My Office 2'}},
  {office: {name: 'My Office 1'}},
];

let path = 'office.name';
let grouped = _(objects)
  .filter(object => _.has(object, path))
  .groupBy(path)
  .value();

console.log(grouped);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #lodash #group #group #null #items
ADD COMMENT
Topic
Name
7+3 =