js将树形结构的数组扁平化(按顺序)

  var newArr =  []新建一个数据,用于存储扁平化化后的数组
 flatData(arr) {
        arr.forEach(item => {
            this.res.push(item)
            item.children && item.children.length > 0 ? this.flatData(item.children) : ""   
            item.children = ''    //若是扁平化后的数组须要显示父子层级,能够把这一项删除
        })
    }