// children为[],则删除children键 function deleteChildren(arr) { let childs = arr for (let i = childs.length; i--; i > 0) { if (childs[i].children) { if (childs[i].children.length) { this.deleteChildren(childs[i].children) } else { delete childs[i].children } } } return arr }
使用
let arrNew = deleteChildren(arr2)
console.log(arrNew)