var array = [
{
status: 1,
child: [
{
status: -1,
name: '周小姐a'
},
{
status: 0,
name: '周小姐b'
},
{
status: 1,
name: '周小姐c'
},
]
},
{
status: 1,
child: [
{
status: 9,
name: '周小姐a'
},
{
status: 0,
name: '周小姐b'
},
{
status: 1,
name: '周小姐c'
},
]
},
{
status: 1,
child: [
{
status: -1,
name: '周小姐a'
},
{
status: 0,
name: '周小姐b'
},
{
status: 1,
name: '周小姐c'
},
]
},
{
status: 1,
child: [
{
status: -1,
name: '周小姐a'
},
{
status: -1,
name: '周小姐b'
},
{
status: 1,
name: '周小姐c'
},
]
}
]
// 下面错误代码
array.forEach((item,index) => {
item.child.filter((ele, eleIndex) => {
if(ele.status < 0) {
array[index].child.splice(eleIndex, 1)
}
})
})
//下面争取的代码
array.forEach((item) => {
item.child = item.child.filter((ele, eleIndex) => {
return ele.status > -1
})
})
console.log(array, 'array');