How does a data format like this recursion

let arr = [{
    role: "admin",
    left: "fzz",
    children: [{
        role: "other",
        right: "pdd",
        children: [{
            role: "admin"
        }]
    }] 
}]

how does a data format like this return an array recursively, leaving the data format unchanged, but taking out the role as admin? (including data in children should also be filtered for role.) if the parent role is not admin, both that level and its children will be discarded
return:

arr = [{
    role: "admin",
    left: "fzz",
    children: [{
        role: "admin",
        right: "pdd"
    }]
}]
Mar.06,2021

this demand is very different from before.
the answer is in response to the previous demand: return all admin and delete admin from children .

getRoles(getData());

function getRoles(data, role = 'admin') {
  let resArr = [];

  main(data);

  return resArr;

  function main(data) {
    if (data && data.length) {
      data.forEach((d, i) => {
        if (d.role === 'admin') resArr.push(data.splice(i, 1));
        if (d.children && d.children.length) main(d.children);
      });
    }
  }
}

function getData() {
  return [{
    role: 'other',
    children: [{
      role: 'admin',
      index: '1'
    }, {
      role: 'other'
    }]
  },{
    role: 'admin',
    index: '2',
    children: [{
      role: 'other',
      children: [{
        role: 'admin',
        index: '3'
      }]
    }]
  }];
}

let arr = [{
    role: 'admin',
    left: 'fzz',
    children: [{
        role: 'other',
        right: 'pdd',
        children: [{
            role: 'admin'
        }]
    }] 
}]
arr.find(function(x){
    return x.role ==='admin';
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaeeb7-69985.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaeeb7-69985.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?