This is my data:

```js
{
  "productGroups": [
    {
      "selectedProducts": [
        { "productPricing": { "recurringFee": {}, "oneTimeFee": {} }, "id": "610e99f9b13b4126a9e07e36" }
      ]
    },
    {
      "selectedProducts": [
        { "productPricing": { "recurringFee": {}, "oneTimeFee": {} } }
      ]
    },
    {
      "selectedProducts": [
        { "productPricing": { "recurringFee": {}, "oneTimeFee": {} } }
      ]
    }
  ]
}

```

I want to remove array element if there is no selectedProducts.id

so result should be:

```js
{
  "productGroups": [
    {
      "selectedProducts": [
        { "productPricing": { "recurringFee": {}, "oneTimeFee": {} }, "id": "610e99f9b13b4126a9e07e36" }
      ]
    }
  ]
}

```

This is what i tried:

```js
const filteredData = {
  productGroups: data.productGroups.map(productGroup => {
    const selectedProduct = productGroup.selectedProducts?.filter(product => product.id);
    return selectedProduct;
  }),
};

```

My result is wrong and I get result with empty arrays:

```js
{
  "productGroups": [
    [
      { "productPricing": { "recurringFee": {}, "oneTimeFee": {} }, "id": "610e9a5eb13b4126a9e07e37" }],
    [],
    []
  ]
}

```