Retrieve an array containing objects with a subset of their properties. Typescript

Consider the array 'radicados' below:

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 method in Typescript to return an array without the 'documentos' properties like this?

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

I want to keep the original data array but omit the 'documentos' property until needed. I could iterate over and create a new array without it, but I'm curious if there's a simpler way.

Answer №1

For information on how to remove a property from all objects in an array, please visit this Stack Overflow post

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

To delve deeper into this topic, consider exploring the documentation

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain a random item from an array containing elements with assigned weights

In my game development project, I have an array of objects representing creatures. Each creature object includes a unique identifier and a corresponding weight or probability for spawning. I am struggling to create an algorithm that will randomly spawn cr ...

How to open a PDF file in a new tab using Angular

Within my Angular 12 application, I am seeking to enable users to "view" a PDF file stored locally in the application within a new tab on Google Chrome. Currently, when implementing the code below in HTML, the file downloads rather than opening in a new ta ...

Calculate the distances between various pairs of points within a grid

I'm on the hunt for a solution that efficiently tackles the following issue. While it should be compatible with python, it doesn't necessarily have to be in python. In a 2D matrix, each element corresponds to a point within a 2D grid. My goal is ...

Obtain a segment of the string pathway

In this scenario, there is a file path provided below. Unlike the rest of the URL, the last part (referred to as video2.mp4) regularly changes. The language used for this project is either Javascript or Typescript. file:///data/user/0/com.sleep.app/files/ ...

Has the antd Form.create() method been substituted with something else?

I have been working on creating a login page in react using antd. I came across a tutorial that seems to be outdated as it is giving me an error. After researching on a forum, I found out that form.create() is no longer available, but I am unsure of how to ...

The error message "Ionic 3 encountering issues with accessing property 'valid' from undefined or null reference"

As I was setting up a form on a CRUD using Firebase, initially just storing name and number as string types, I decided to add more parameters of the same type. However, I encountered an issue with the error message "Unable to get property 'valid' ...

Guide on subscribing to an object from a service in Angular 2/5

I am facing an issue where I need to update my property component with data received from the server. In the Service, I have implemented something like this: private events: Event[] = []; eventChanged = new Subject<any>(); // Edit: added an observa ...

In the context of Angular, the ELSE statement continues to run even after the IF condition has been satisfied within

Currently, I am utilizing Angular 11 in conjunction with Firestore. Within my code, I am fetching data using the subscribe method from an API service. Subsequently, I am employing a for loop to extract object values in order to verify if a value within a c ...

Leveraging Shared Modules Component across multiple modules in Angular can enhance code re

In my project structure, I have a shared folder containing shared.module.ts. Additionally, there is a modules folder with sub-modules, one of which is Dashboard.module.ts. Inside the shared module, I created a custom sidebar menu that I intend to use withi ...

Facing a challenge with handling HTTP data in a TypeScript-based Angular web application

I am currently working on developing a web application using Angular and the SpringMVC Framework. One of the tasks I'm facing is loading a list of users (referred to as "consulenti" in the code). While the backend HTTP request works fine, I encounter ...

In C++, comparing a character array with a space (' ') and a null terminator ('') can be tricky, especially when the counter does not function as expected

Seeking assistance with a C++ function to count the number of words in a full name. The issue arises when attempting to find the word count, as the counter returns an unexpectedly high value. Your help in resolving this coding query would be greatly apprec ...

Increase the totalAmount by adding the product each time

Can someone help me understand why the totalAmount shows as 20 when I add a product? Also, why doesn't it increase when I try to increment it? Any insights would be appreciated. Thank you. ts.file productList = [ { id: 1, name: 'Louis ...

The program is throwing an error stating that the property 'user' is not found on the data type 'DefaultRootState'

Issue Encounter I am currently encountering the error message 'user' does not exist on type 'DefaultRootState'. I have attempted to resolve it without success so far. Here is the link to my GitHub repository. Error Details C:/Users/t ...

Is there a way to specify the sequence in which Observables are subscribed to in Angular?

Working with API calls in a service.ts file has brought me some challenges. Here is the code snippet: //code getCars() { this.car = this.http.get(car_url) return this.car; } getTires() { this.tires = this.http.get(tires_url) return this.tires; } getSeat ...

Transformation of Python code into Blockly blocks

As the founder of edublocks.org, I am interested in adding Python to Blocks functionality on the platform. At the moment, users can only transition from Blocks to Python. Is there anyone who has experience with this and can provide guidance on how to achi ...

Is it possible to access the passed arguments in the test description using jest-each?

Utilizing TypeScript and Jest, consider this sample test which can be found at https://jestjs.io/docs/api#testeachtablename-fn-timeout it.each([ { numbers: [1, 2, 3] }, { numbers: [4, 5, 6] } ])('Test case %#: Amount is $numbers.length =&g ...

What steps should I take to customize WebStorm so that it no longer automatically imports the entire Typescript paths?

Recently, I noticed a change in WebStorm after an update that affected how paths were imported in my files. Initially, when typing @Component and letting WebStorm automatically import the path, it would use the following format: import { Component } from ...

Getting Typescript Compiler to Recognize Global Types: Tips and Strategies

In the top level of my project, I have defined some global interfaces as shown below: globaltypes.ts declare global { my_interface { name:string } } However, when attempting to compile with ts-node, the compiler fails and displays the er ...

Having trouble retrieving the parent object in Angular OnInit method?

I am facing an issue with attaching a custom validator to an Angular Form Control. The Form Controls are initialized in the ngOnInit method, and I want the validator to check if a field has input only when a boolean class member this.shouldCheck is true. ...

angular does not update dynamically created dropdowns with populated arrays

Upon loading the page, my initial dropdown functions correctly. However, the child dropdown is loaded from localstorage after the first dropdown. The issue arises when I load the second dropdown and set it to the default value - at this point, I am unabl ...