Reputation: 37
i have an array of objects, so i want to delete the objects without 'first' attribute and if the object is {} and if the 'last' attribute is undefined
Array(3) {first: '', last: ''} {} {last: undefined}
i tried doing like this:
let mapped = []
mapped = values?.invites?.filter(({ first, last }) => {
if(first && last)
return { first, last }
})
but does not worked
note: i need to return an objects { first, last }
Upvotes: 0
Views: 79
Reputation: 517
mapped = values?.invites?.filter(({ first, last }) =>(typeof first !=="undefined" && last !=="undefined");
Because PO want to keep {firts:'',second""}
Upvotes: 2