js树形结构数组扁平化

function treeToArray(tree) {
  var res = []
  for (const item of tree) {
    const { children, ...i } = item
    if (children && children.length) {
      res = res.concat(treeToArray(children))
    }
    res.push(i)
  }
  return res
}

你可能感兴趣的:(js树形结构数组扁平化)