Home » Javascript » how to get rid of an array inside an array in javascript

how to get rid of an array inside an array in javascript

Posted by: admin August 19, 2018 Leave a comment

Questions:
const addressZip = person.get('addresses').filter((address) => address.get('legacy_id')).filter((newAddress) => (
  getZIPErrors(newAddress.get('zip'))
))

when this function is executed it returns me as an
[array(0)] if it has no error
when it has an error it returns me as an [array(1)].

Instead of returning an array inside an array I just want to return a single array in this way if it has no error [] and if it has an error it should be like ['invalid']

Answers: