需求,过滤掉testVar中的projectlog元素,代码如下
var testVar=[
{
"cate": "re",
"items": [
{
"name": "project",
"title": "test111",
"icon": "image"
},
{
"name": "projectlog",
"title": "test222",
"icon": "log"
}
]
}
]
console.log('testVar',testVar);
var newTest=[]
testVar.forEach((now,index)=>{
newTest[index]=now
newTest[index].items=now.items.filter((item)=>{
return item.name!=="projectlog"
})
}
)
console.log('newTest',newTest);
输出结果:
testVar [ { cate: 're', items: [ [Object], [Object] ] } ]
newTest [ { cate: 're', items: [ [Object] ] } ]
参考: