letters
letters

Reputation: 37

How can i remove the useless objects?

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

Answers (1)

PeterT
PeterT

Reputation: 517

mapped = values?.invites?.filter(({ first, last }) =>(typeof first !=="undefined" && last !=="undefined");

Because PO want to keep {firts:'',second""}

Upvotes: 2

Related Questions