I'm trying to merge n objects from an array of objects listed below.

I tried to use reduce method, but I can't understand what I'm doing wrong, still new to advance js methods.

```js
  const array = [
    {
      data: {
        '1': {
          foo: 'bar',
          test: true
        },
        '4': {
          foo: 'boor'
        }
      }
    },
    {
      data: {
        '1': {
          x: 'o',
          test2: false
        }
      }
    }
  ];

  const result = Object.values(
    array.reduce((r, { data }) => {
      Object.entries(data).forEach(([id, { ...else }]) => {
        r[id] = r[id] || {
          id,
          fooValue: else.foo, // should be `bar` for id `1` and `boor` for id `4`
          xValue: else.x, // should be `o` for id `1` and `undefined` for id `4`
          all: ...else
        };
      });
      return r;
    }, {})
  );

```

I'm trying to get something like this in a end, but I'm pretty lost.

```
  [
    {
      id: '1',
      fooValue: 'bar',
      xValue: 'o',
      all: {
        foo: 'bar',
        test: true,
        x: 'o',
        test2: false
      }
    },
    {
      id: '4',
      fooValue: 'boor',
      xValue: undefined,
      all: {
        foo: 'boor'
      }
    }
  ]

```