How to delete relevant data from the data array according to the id array?

when deleting data is selected, the selected data id forms an array, and then deletes the data from the first layer of all data arrays, and if the data has this data in the children,children, delete the data from the first layer

data = [{

]
    flg: "0",
    id: "1001",
    name: "1",
    children: [{
      flg: "0",
      id: "100101",
      name: "1"
    }, {
      flg: "0",
      id: "100102",
      name: "2"
    }, {
      flg: "0",
      id: "100103",
      name: "3"
    }]
  }, {
    flg: "0",
    id: "100101",
    name: "1"
  }, {
    flg: "0",
    id: "100102",
    name: "2"
  }, {
    flg: "0",
    id: "100103",
    name: "3"
  }]

cacel = ["100103"]

the data to be obtained is
[{

]
    flg: "0",
    id: "100101",
    name: "1"
  }, {
    flg: "0",
    id: "100102",
    name: "2"
  }]
Nov.15,2021

mainly uses recursion

executable example:
https://codepen.io/LiangWei88.

Code:

let data = [
    {
        flg: "0",
        id: "1001",
        name: "1",
        children: [{
            flg: "0",
            id: "100101",
            name: "1"
        }, {
            flg: "0",
            id: "100102",
            name: "2"
        }, {
            flg: "0",
            id: "100103",
            name: "3"
        }]
    }, 
    {
        flg: "0",
        id: "100101",
        name: "1"
    }, 
    {
        flg: "0",
        id: "100102",
        name: "2"
    }, 
    {
        flg: "0",
        id: "100103",
        name: "3"
    }
];

let idToDelete = "100103";

let result = filterData(data);
console.log(result);

function filterData(data) {
    return data.reduce((acc, current) => {
        if (current.id == idToDelete) {
            return acc;
        } else {
            if (current.children) {
                let res = filterData(current.children);
                if (res.length < current.children.length) {
                    return acc;
                }
            }
            acc.push(current);
            return acc;
        }
    }, []);
}
Menu