Js multi-layer nesting, only know the last value, how to traverse to get all the parents

the data structure has multiple levels of nesting, as follows: the only value obtained so far is "521". How to traverse to get "1045-SCG" and "968"

:

[
  {
    "value": "1045-SCG",
    "label": "",
    "children": [
      {
        "value": "968",
        "label": "",
        "children": [{
          "value": "521",
          "label": "",
        }]
      }
    ]
  },
  {
    "value": "1044-SCG",
    "label": "111",
    "children": []
  },
  ,
  {
    "value": "1036-SCG",
    "label": "",
    "children": [
      {
        "value": "264",
        "label": "",
        "children": [
          {
            "value": "271",
            "label": "",
            "children": []
          }
        ]
      }]
  }
]
Jun.25,2022

simple objects have no record of which object attributes they are. You have to redesign the data structure


function l(data, val) {
  for(var i=0;i<data.length;iPP){
    if(data[i]&&data[i].value == val){
      return [];
    }
    if(data[i]&&data[i].children){
      var d = l(data[i].children,val);
      if(d)
        return d.concat(data[i].value);
    }
  }
}

l(data,'271');
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-1b3b2ff-2c26d.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-1b3b2ff-2c26d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?