Filter to distinct values in Nested Array

Hi everyone!

I have a JSON in such format:

“data”: {
“allClients”: {
“edges”: [
{
“node”: {
“code”: “TEST1”,
“name”: “AAAAA”,
“allDatabases”: {
“edges”: []
}
}
},
{
“node”: {
“code”: “TEST2”,
“name”: “BBBB”,
“allDatabases”: {
“edges”: [
{
“node”: {
“tnsname”: “tst1rns”,
“client”: 17,
“allSubscriptions”: {
“edges”: [
{
“node”: {
“intrfSeqno”: 32
}
}
]
}
}
}
] }
}
}
]}
}

My task is to get records from allClients/edges/node/code which have information in array allSubscriptions/edges.I have got possibility to do this via creation of new array and using foreach to parse each array in this json:

var DisClients = [];
var clients = [];

     data.allClients.edges.forEach(function(item){
        item.node.allDatabases.edges.forEach(function(itemD){
          itemD.node.allSubscriptions.edges.forEach(function(itemS){    
            if(DisClients.indexOf(data.allClients.edges.indexOf(item)) === -1) {
              DisClients.push(data.allClients.edges.indexOf(item));
            }   
        });
        });
       });
      data.allClients.edges.forEach(function(item){
        if (DisClients.includes(data.allClients.edges.indexOf(item)) === true){
          clients.push(data.allClients.edges[data.allClients.edges.indexOf(item)]);
        }
      });
      var newClients = new Vue();
      Object.assign(newClients, {
        edges : clients
      })

My data is returned via v-data-table where I pass my final array:

<v-data-table
:headers=“headers”
:items="clientsList.edges>

Can you let me know if it is possible to filter my initial array instead of creation of new one? I didn’t have possibility to find how to do this using filter functionality against nested array.

Could someone help me with this, please.

Thank you in advance!

I have already found the solution using filter:

data.allClients.edges = data.allClients.edges.filter( ({ node })=> {

          let edges = node.allDatabases && node.allDatabases.edges.filter(
            ({ node }) => (node.allSubscriptions && node.allSubscriptions.edges.length > 0)
          );
          if (edges && edges.length > 0) {
            node.allDatabases = {
              edges
            }
            return true;
          }
        })

The topic can be marked as resolved.