Group array of objects using lodash

const readings = [
  { location: { lat: '21.4', lng: '23.5' }, vehicle: 'sdkhf', id:'1' },
  { location: { lat: '22.4', lng: '25.5' }, vehicle: 'sdkhf', id:'2' },
  {  location: { lat: '21.4', lng: '23.5' }, vehicle: 'sdkhf', id:'3' },
  { location: { lat: '22.4', lng: '25.5' }, vehicle: 'sdkhf', id:'2' },
  { location: { lat: '28.4', lng: '21.5' }, vehicle: 'sdkhf', id:'5' },
];

I want to group the below array of objects by location property.

The expected result is an array of objects
with location and points(array of objects which have the same location).

Group array of objects using lodash or array reduce method

70 thoughts on “Group array of objects using lodash”

Leave a Comment