Extracting grouped objects into a flattened list I need to optimize this javascript method because it is a bit slow, I don't want to use the flat() command, as for some reason my angular6 app does not understand the vanilla flat() command, or display some annoying warning messages.

So check the below:


  
  my original object
  my result object desired
  my slow solution (works, but is slow)
  


1. my original object:

  const data = [
      {
        "id": 1,
        "name": "Application",
        "groups": [
          {
            "groupName": "",
            "configurations": [
              {
                "id": 17,
                "icon": "access_time",
                "title": "Daily Order Cut-Off Time",
                "description": "Daily Order Cut-Off Time",
                "code": "daily-order-cut-off-time",
                "value": "09:35",
                "valueType": "Time",
                "configurationTypeId": 11,
                "definition": {
                  "step": "none"
                },
                "isDefault": false
              }
            ]
          }
        ]
      },
      {
        "id": 3,
        "name": "Processing",
        "groups": [
          {
            "groupName": "",
            "configurations": [
              {
                "id": 1078,
                "icon": "flash_on",
                "title": "Auto Process",
                "description": "Will process all orders that are in the same batch",
                "code": "processing-auto-process",
                "value": "0",
                "valueType": "Boolean",
                "configurationTypeId": 6,
                "definition": null,
                "isDefault": false
              },
              {
                "id": 1074,
                "icon": "subdirectory_arrow_right",
                "title": "Allow Under Picking",
                "description": "Allow under pick when processing order?",
                "code": "processing-allow-under-picks",
                "value": "0",
                "valueType": "Boolean",
                "configurationTypeId": 6,
                "definition": null,
                "isDefault": false
              }
            ]
          }
        ]
      }
    ];


2. object desired:

 [
      {
        "id": 17,
        "code": "daily-order-cut-off-time",
        "value": "09:35"
      },
      {
        "id": 1078,
        "code": "processing-auto-process",
        "value": "0"
      },
      {
        "id": 1074,
        "code": "processing-allow-under-picks",
        "value": "0"
      }
    ]


My slow solution:

const result = data.map(module =&gt; module.groups.map(configurations =&gt; configurations.configurations.map(config =&gt; ({ id: config.id, code: config.code, value: config.value })))).reduce((l,n) =&gt; l.concat(n), []).reduce((l2,n2) =&gt; l2.concat(n2),[]));
As commented, the ES6 spread operator flattens like you want.  The syntax is a little weird for multiple invocations:

result = [].concat(...[].concat(...data.map( d =&gt; d.groups.map( g =&gt; g.configurations.map( c =&gt; ({id:c.id, code:c.code, value:c.value})))))) 


The arr.flat() method does the same thing more simply.  It takes an optional depth argument to indicate how many levels to descend when flattening.  In your case, depth is 2.  

.flat is a recent feature that may not exist on your platform.  Most notably, Node 10 and MS Edge do not have it, while both of those do have the spread operator:

data.map( d =&gt; d.groups.map( g =&gt; g.configurations.map( c =&gt; ({id:c.id, code:c.code, value:c.value})))).flat(2)