fetch object array from nested object array javascipt

  arrayobject, arrays, javascript, json, nested

I have a nested object array like below,

data = [
  {
    "value": "code 1",
    "field": "A",
    "hasSubgroups": false,
    "aggregates": {
      "Total": {
        "sum": 0
      }
    },
    "items": [
      {
        "SlNo": 1,
        "Id": 001,
        "ItemDescription": "item 1"
      }
    ]
  },
  {
    "value": "code 2",
    "field": "A",
    "hasSubgroups": false,
    "aggregates": {
      "Total": {
        "sum": 0
      }
    },
    "items": [
      {
        "SlNo": 2,
        "Id": 002,
        "ItemDescription": "item 2"
      },
      {
        "SlNo": 3,
        "Id": 3,
        "ItemDescription": "item 3"
      },
      {
        "SlNo": 4,
        "Id": 004,
        "ItemDescription": "item 4"
      }
    ]
  }
]

I need to get a result like,

data = [
{
"SlNo": 1,
"Id": 99990000006648,
"ItemDescription": "item 1"
},
{
"SlNo": 2,
"Id": 99990000006649,
"ItemDescription": "item 2"
},
{
"SlNo": 3,
"Id": 99990000006650,
"ItemDescription": "item 3"
},
{
"SlNo": 4,
"Id": 99990000006651,
"ItemDescription": "item 4"

  }
]

I have tried different ways to fetch the inner object array from object array,

data.map((u,i) => u[i].map((a,b)=> a.items))

Source: Ask Javascript Questions

LEAVE A COMMENT