Extracting values from array of objects

I have an array that looks like this one(albeit, it has more values, but the structure is always the same):

[array1[    {
"specialities": "Surgery",
        "users": [
            {
               "name": "John",
               "location": "USA",
                "age": "34",
            },
           {
                "name": "John",
               "location": "California",
                "address": "Silk Road 123"
            },
           {
               "name": "Jane",
               "last-name": "Edmus"
               "location": "USA"
            }
        ]
    },
]
]

I want to merge the objects whose name match. I came up with this function, which identifies the duplicates and push them to an array:

duplicateArray = values => {
  let ids = {name: ""};
  let dups = [];

  values.map(i=> iusers.map(user =>{
    if (user.name=== ids.name) {
      dups.push(user.name)
    } else {
      ids.name=user.name;
    }
  }))

  return console.log(dups);
}

This works. My original idea was to do an arr.includes() and compare user.name to dups. Thing is, I want locations to look like an array, like this:

[ { “users”: [ { “name”: “John”, “location”: [“USA”, “California”}, “age”: “34”, “address”: “Silk Road 123” }, { “name”: “Jane”, “last-name”: “Edmus” “location”: “USA” } ] }, ]

How could I accomplish this?

How does something like this sound: (not tested, just spitballing)

const reducer = (acc, user) => {
      const name = user.name;
      acc[name] = Object.assign({}, acc[name] || {}, user); // Or a proper deep merge here
      return acc;
  };

const nameKeyedUsers = values.reduce(reducer, {});
const users = Object.values(nameKeyedUsers);

The idea above is to create a dictionary of key-value pairs based on name as the key, then simply return an array of the values