user8084037
user8084037

Reputation:

return array objects with some of the properties in the objects. Typescript

let's say I have an array called 'radicados' like this:

this.radicados = [{
      id:0,
      asunto:'Facturas ADPRO Propias',
      consecutivo:'FAC-AB-00046',
      documentos: [{id:1, descripcion:'documento1.pdf', esAnexo:false, ruta:'' },
                   {id:2, descripcion:'documento2.xls', esAnexo:false, ruta:'' },
                   {id:3, descripcion:'documento3.doc', esAnexo:true,  ruta:'' }]
    },{
      id:1,
      asunto:'Contrato de Construcciones',
      consecutivo:'CR-093132',
      documentos: [{id:1, descripcion:'documento4.pdf', esAnexo:false, ruta:''},
                   {id:2, descripcion:'documento5.jpg', esAnexo:false, ruta:''},
                   {id:3, descripcion:'documento6.doc', esAnexo:true,  ruta:''},
                   {id:3, descripcion:'documento7.pdf', esAnexo:true,  ruta:''}]
    }]

Is there a way to return an array with all the elements but without the documents properties in Typescript? Like this:

this.radicados2 = [{
      id:0,
      asunto:'Facturas ADPRO Propias',
      consecutivo:'FAC-AB-00046'
    },{
      id:1,
      asunto:'Contrato de Construcciones',
      consecutivo:'CR-093132'
    }]

I'm saving all the array but I don´t want to have the 'documentos' property always because I only use it in One moment. I know I could itereate over the array and create a new one where I onle save the properties I need, but I would like to see if there is an easier way to do it.

Upvotes: 0

Views: 46

Answers (1)

KDani-99
KDani-99

Reputation: 145

See Remove property for all objects in array

var result = radicados.map(({documentos, ...elem}) => elem)

If you'd like to learn more about it , you can check the documentation

Upvotes: 4

Related Questions