your logic fault is that the filter function returns a new array. In filter, it returns a Boolean value, but you return the array returned by filter as if it were true or false.
let obj= [
//
{
name: "shoes",
data: [
{
value: [1, 2]
}
]
},
//
{
name: "shoes2",
data: [
{
value: [2, null]
}
]
},
];
var ss = obj.filter(item=>{
return item.data[0].value[1]!==null
});
console.log(ss);
the above code meets your requirements. If you are similar to the following structure, as long as one of them is null, then the code logic is:
let obj= [
//
{
name: "shoes",
data: [
{
value: [1, 2]
}
]
},
//
{
name: "shoes2",
data: [
{
value: [2, null]
}
]
},
//
{
name: "shoes3",
data: [
{
value: [3, 4]
},
{
value: [3, null]
}
]
},
//
{
name: "shoes4",
data: [
{
value: [4, 4]
},
{
value: [4, 4]
},
{
value: [4, 4]
}
]
}
];
var ss = obj.filter(item=>{
if(item.data.some((v,index,arr)=>{
return v.value[1] === null
}))
{
return false;
}else{
return true;
}
});
console.log(ss);
you don't need filter to get attribute values directly inside
.
let arr = obj.filter(item => {
return !!item.data.value[1]
})