📜  lodash group by except group null items - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:19.404000             🧑  作者: Mango

代码示例1
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);