js循环数组删除值为空的json
varitem=[{"resource_id":'',"text":'',"content_desc":'',"smallImg":'',"existFlag":true...
var item =[
{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'aaa',
"text":'bbb',
"content_desc": 'ccc',
"smallImg":'ddd',
"existFlag":true
},{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
}
] 展开
{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'aaa',
"text":'bbb',
"content_desc": 'ccc',
"smallImg":'ddd',
"existFlag":true
},{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
}
] 展开
1个回答
展开全部
var result = [];
var item =[
{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'7886',
"text":'454',
"content_desc": '45',
"smallImg":'132',
"existFlag":true
},
{
"resource_id":'aaa',
"text":'bbb',
"content_desc": 'ccc',
"smallImg":'ddd',
"existFlag":true
},{
"resource_id":'',
"text":'',
"content_desc": '',
"smallImg":'',
"existFlag":true
}
];
for(var i=0;i<item.length;i++){
var obj=item[i];
if(!!obj["resource_id"]){
result.push(obj);
}
}
console.log(result);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询