I have the following object:

```
[{animal: 1, hasLegs: true},{animal: 1, hasTail: false},
 {animal: 2, hasLegs: true},{animal: 2, hasTail: true},{animal: 3}]

```

I would like to restructure it to the following:

```
[
  { animal:1, info: { hasLegs: true, hasTail: false },
  { animal:2, info: { hasLegs: true, hasTail: true },
  { animal:3, into: {},
]

```

such that all objects in the array with that is `animal:1` is unified under that key and adding the remaining keys with values under the key `info`.

Been trying to use the `map()`-function but can not get the hang of it, and do not know if `map()` alone can solve this.
['https://Stackoverflow.com/questions/58511850', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2762175/']
This is a similar answer, but should be slightly more performant since it takes advantage of map hashing instead of doing a find for each entry.

```js
const data = [{animal: 1, hasLegs: true},{animal: 1, hasTail: false},
  {animal: 2, hasLegs: true},{animal: 2, hasTail: true},{animal: 3}]

const infoMap = data.reduce((rollup, { animal, ...info }) => {
  const entry = rollup[animal] = rollup[animal] || {}
  Object.assign(entry, info)
  return rollup
}, {})

const result = Object.keys(infoMap)
  .map((animal) => ({
    animal,
    info: infoMap[animal]
  }))

console.log(result)

```
```js
const array = [{ animal: 1, hasLegs: true }, { animal: 1, hasTail: false },
{ animal: 2, hasLegs: true }, { animal: 2, hasTail: true }, { animal: 3 }];
const result = [];
array.forEach(obj => {
    let newEntry = null;
    if (result.findIndex(entry => entry.animal === obj.animal) === -1) {
        newEntry = { animal: obj.animal, info: {} }
        result.push(newEntry);
    }
    const entry = newEntry || result.find(entry => entry.animal === obj.animal);
    Object.keys(obj).forEach(key => {
        if (key === 'animal') return;
        entry.info[key] = obj[key];
    });

});
console.log(result);

```