I am trying to remove the empty nodes from the list in C#. I am trying to make a structure like tree view but due to some issues I need to have the node removed and it’s coming as Null.
var tree = [{
    Id: 1,
    text: "Parent 1",
    ParentId: 0
    nodes: [{
        Id: 2,
        text: "Child 1",
        ParentId: 1
        nodes: [{
            Id: 3
            text: "Grandchild 1",
            ParentId: 2,
            nodes: []
          },
          {
            Id: 4,
            text: "Grandchild 2",
            ParentId: 2,
            nodes: []
          }
        ]
      },
      {
        Id: 5
        text: "Child 2",
        ParentId: 1,
        nodes: []
      }
    ]
  },
  {
    Id: 6,
    text: "Parent 2",
    ParentId: 0
    nodes: []
  }
];
How to remove the empty nodes in C# or JavaScript?
 
     
    