How to Use filter Method to Recursively Filter Tree Array Objects

  javascript
const treeData = [{
 title: "1",
 key: "1",
 children: [{
 title: "1-1",
 key: "1-1",
 children:[{
 title:"1-1-1",
 key:"1-1-1",
 },{
 title:"1-1-2",
 key:"1-1-2",
 }]
 }, {
 title: "1-2",
 key: "1-2",
 },{
 title: "1-3",
 key: "1-3",
 },{
 title: "1-4",
 key: "1-4",
 }],
 }];

If the parent is filtered out, all children below the parent are also filtered out.
I did not achieve the filtering effect through recursive map and recursive filter. The code is as follows:

deleteTreeData = (data,selectedKey) => {
 const newTreeData = data.filter((item) => {
 if(item.children){
 this.deleteTreeData(item.children,selectedKey);
 bracket
 
 return item.key !  == selectedKey;
 
 });
 
 this.setState({
 treeData : newTreeData,
 },function(){
 Log ("= = = = newtreedata:" add JSON.stringify(newTreeData));
 });
 bracket

This writing can only delete the top menu, what is the correct idea, thank you ~

const treeData = [{
 title: "1",
 key: "1",
 children: [{
 title: "1-1",
 key: "1-1",
 children:[{
 title:"1-1-1",
 key:"1-1-1",
 },{
 title:"1-1-2",
 key:"1-1-2",
 }]
 }, {
 title: "1-2",
 key: "1-2",
 },{
 title: "1-3",
 key: "1-3",
 },{
 title: "1-4",
 key: "1-4",
 }],
 }];
 
 function f(arr, selectedKey) {
 return arr.filter(item => item.key !  == selectedKey).map(item => {
 item = Object.assign({}, item)
 if (item.children) {
 item.children = f(item.children, selectedKey)
 bracket
 return item
 })
 bracket
 
 console.log(f(treeData, '1-2'))