js 使用filter過濾多重陣列
阿新 • • 發佈:2020-12-10
技術標籤:node
過濾如下資料
var comment_list = [{ "content":"1111", "status":1, "sub_comment_list":[{ "content":"11111111", "status":1, }] }, { "content":"2222", "status":1, "sub_comment_list":[{ "content":"22222", "status":0, }] }]
let newArray = []
comment_list.forEach(function(now,index){
newArray[index] = now
if(newArray[index].status ==1){
newArray[index].sub_comment_list = now.sub_comment_list.filter((item) => {
return item.status === 1
})
}
})
console.log(newArray)