Please tell me how to loop and recursively put all the id of an array in an array into another array.

Thank you. I thought of it as soon as it was released.
data: [

]
{
    value: ""
    children: [
        {
            value:"",
                children: [
                    {value: ""}
                ]
        },
        {
            value:"",
                children: [
                    {value: ""}
                ]
        },
    ]
}

]
how to determine whether there is a children array under the array, and then put the value in it into a new array?

Mar.10,2021

let data = {
    value: '',
    children: [{
            value: '',
            children: [
                { value: '' }
            ]
        },
        {
            value: '',
            children: [
                { value: '' }
            ]
        },
    ]
}


function f({ value, children }, array = []) {
    array.push(value)
    if (children && children.length > 0) {
        for (let child of children) {
            f(child, array)
        }
    }
    return array;
}

console.log(f(data))//[ '', '', '', '', '' ]

var data = [

  {
    value: '',
    children: [
      {
        value: '',
        children: [
          { value: '' }
        ]
      },
      {
        value: '',
        children: [
          { value: '' }
        ]
      },
    ]
  }
]
var arr = []
function f(items) {
  items.forEach(item => {
    arr.push(item.value)
    if (item.children) {
      f(item.children)
    }
  })
}
f(data)
console.log(arr)

var m = [];
function test(arr){
    arr.forEach(v=>{
        m.push(v.value);
        f(v.children)test(v.children)
    })
}
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-1b422a1-2c5f6.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-1b422a1-2c5f6.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?