How to extract a certain health value from multi-layer nesting?

[{
          id: 1,
          label: " 1",
          children: [{
            id: 4,
            label: " 1-1",
            children: [{
              id: 9,
              label: " 1-1-1"
            }, {
              id: 10,
              label: " 1-1-2"
            }]
          }]
        }, {
          id: 2,
          label: " 2",
          children: [{
            id: 5,
            label: " 2-1"
          }, {
            id: 6,
            label: " 2-2"
          }]
        }]

how do three-level menu data nesting fetch all id push into an array

Aug.16,2021

const ids = arr.reduce((total, cur) => {
  total.push(cur.id)
  if (cur.hasOwnProperty("children")) {
    total.push(...cur.children.reduce((a, b) => {
      a.push(b.id)
      if (b.hasOwnProperty("children")) {
        a.push(...b.children.reduce((x, y) => {
          x.push(y.id)
          return x
        }, []))
      }
      return a
    }, []))
  }
  return total;
}, [])
console.log(ids)
Menu