How to traverse an array with such a tree structure

for an array with a tree structure like this, I want to replace all name with title,. The hierarchy of the array varies, and some may not have children in it.

const treeData = [{
    title: "0-0",
    key: "0-0",
    children: [{
      title: "0-0-0",
      key: "0-0-0",
      children: [
        { title: "0-0-0-0", key: "0-0-0-0" },
        { title: "0-0-0-1", key: "0-0-0-1" },
        { title: "0-0-0-2", key: "0-0-0-2" },
      ],
    }, {
      title: "0-0-1",
      key: "0-0-1",
      children: [
        { title: "0-0-1-0", key: "0-0-1-0" },
        { title: "0-0-1-1", key: "0-0-1-1" },
        { title: "0-0-1-2", key: "0-0-1-2" },
      ],
    }, {
      title: "0-0-2",
      key: "0-0-2",
    }],
  }, {
    title: "0-1",
    key: "0-1",
    children: [
      { title: "0-1-0-0", key: "0-1-0-0" },
      { title: "0-1-0-1", key: "0-1-0-1" },
      { title: "0-1-0-2", key: "0-1-0-2" },
    ],
  }, {
    title: "0-2",
    key: "0-2",
    children: []

  }];

Recursive traversal

function setName(obj){
       for(var i in obj){
           obj[i].name = obj[i].title;
           if(obj[i].chilren){
               setName(obj[i].children)
           }
       }
       console.log(obj);
  }
  setName(treeData)

function treedata(a){
            let d=a.map(r=>{
            if(r.children){
                 return {'name':r.title,'key':r.key,'children':treedata(r.children)}
            }else{
                return {'name':r.title,'key':r.key}
            }
          })
          return d
        }
        console.log(treedata(treeData))

  

where can I find name ?

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-1e4bce2-44e77.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-1e4bce2-44e77.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?