Using NodeJS
I need to take a json array like below.
    const data = [
  {
    pid: 40944,
    city: 'Port Melbourne',
    region1: 'Victoria',
    region2: ''
  },
  {
    pid: 40785,
    city: 'Melbourne',
    region1: 'Victoria',
    region2: ''
  },
  {
    pid: 40786,
    city: 'West Melbourne',
    region1: 'Victoria',
    region2: ''
  },
  {
    pid: 40722,
    city: 'Melbourne',
    region1: 'Victoria',
    region2: ''
  },
  {
    pid: 40788,
    city: 'North Melbourne',
    region1: 'Victoria',
    region2: ''
  }
]
And change the structure, remove duplicates (suburb) & order A-Z (suburb).
{
  '40785': 'Melbourne, Victoria',
  '40788': 'North Melbourne, Victoria',
  '40944': 'Port Melbourne, Victoria',
  '40786': 'West Melbourne, Victoria',
}
I've been able to create the structure using the following but I still need to remove duplicates and sort A-Z
    const location = Object.fromEntries(rows.map((data) => [
        data.pid,
        data.region2 ? `${data.city}, ${data.region1}, ${data.region2}` : `${data.city}, ${data.region1}`
    ]))
thankyou!
 
     
    