let arrTree = [
{
name: "第一层",
code: "01",
children: [{ name: "第二层", code: "02", children: [{ name: "第三层", code: "03", children: [{ name: "第四层", code: "04" }] }] }]
}
];
this.areaFor(arrTree,[])
/**
* @name areaFor 递归
* @param Array {*} 深层数组
* @param Array {*} 将元素从深层数组中抽出后数组
*/
areaFor = (arrTree, arr) => {
for (let i = 0; i < arrTree.length; i++) {
arr.push(arrTree[i])
if (arrTree[i].children) {
this.areaFor(arrTree[i].children, arr)
}
}
return arr
}
深层嵌套数组展开
最新推荐文章于 2022-08-23 09:53:32 发布