mark
2022-09-30 2ec95b3d2fd484b44d5274054bcbd78307a76ef8
1
2
3
4
5
6
7
8
9
10
11
12
export const traverse = (arr, newArr = []) => {
  // 递归 遍历数组 满足条件 a.type === "4" push进入新数组 然后弹出新数组
  for (let i = 0; i < arr.length; i++) {
    let a = { ...arr[i] }
    if (a.type === "4") {
      newArr.push(a)
    } else {
      traverse(a.children, newArr)
    }
  }
  return newArr
}