boolean callback lodash code example

Example 1: lodash merge

import merge from 'lodash/merge'

let object = {  'a': [{ 'b': 2 }, { 'd': 4 }]}; 
let other = {  'a': [{ 'c': 3 }, { 'e': 5 }]}; 
merge(object, other); // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

Example 2: 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);