I have an array of objects where some objects are undefined and I want to know how to remove them i got it how many of them but don't know how to remove them from an array of objects. i know this method to use but i want some more standard way to do it
const data = [
{
roleDoc:{
name:"A"
}
},
{ roleDoc: undefined }
,{
roleDoc:{
name:"c"
}
},{
roleDoc:{
name:"c"
}
},
{ roleDoc: undefined },
,{
roleDoc:{
name:"c"
}
}
]
const xy = []
data.forEach(item => {
if(item.roleDoc !== undefined){
xy.push(item)
}
else{
console.log('hello')
}
})
console.log(xy)
expected output is
const data = [
{
roleDoc: {
name: "A"
}
},
,
{
roleDoc: {
name: "c"
}
},
{
roleDoc: {
name: "c"
}
},
,
{
roleDoc: {
name: "c"
}
}
];