JS从多维数组中递归查找内容并删除

// 从一个多维数据组删除一个指定key的值
const loop = (data, key) => {
    data.forEach((item, index) => {
        if (item.key === key) {
            data.splice(index, 1)
        }
        if (item.children.length > 0) {
            return loop(item.children, key)
        }
    })
}
loop(data, key)
posted @ 2021-06-21 10:01  天上星辰  阅读(1916)  评论(0)    收藏  举报