Converting Angular object into an array

Is there a way to extract only the data array from the observable response? I'm interested in retrieving the values of cat_id, cat_name, and cat_description, but not the sql_types array.

{
    "code": 0,
    "message": "",
    "data": [
        {
            "cat_name": "Topografía",
            "cat_description": "Servicios de topografía en general",
            "cat_id": 1
        },
        {
            "cat_name": "Estructuras hormigón",
            "cat_description": "subcontratas de estructuras de hormigón ",
            "cat_id": 3
        }
    ],
    "sqlTypes": {
        "cat_name": 12,
        "cat_description": 12,
        "cat_id": 4
    }
}

Answer №1

Transform your observable by piping it and mapping it to the desired object.

In this example, only the data you need will be accessible:

Observable.pipe(map(resp => resp.data)).subscribe(data=> //perform actions)

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

Guide to exporting a data table to a PDF file with Angular Material

I am looking for a way to export my data table to a PDF file using Angular Material. I have tried using jsPDF but it seems to only work with static data. Is there a way to export my dynamic DataTable content to a PDF file? Below is the HTML source code fo ...

Tips for Enhancing Window Leveling (Brightness and Contrast)

const pixelArray = [11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11..] if (pixelArray != null) { for (let i = 0; i < pixelArray.length; i++) { let ...

Sending a selected Radio Button via JSON: A step-by-step guide

As I work on developing a REST API that will be accepting JSON data via POST requests, I am currently determining the best practice for indicating which Radio Button has been selected by the sender. While brainstorming, I have come up with three potential ...

Is it possible to retrieve JSON data from an external URL using JavaScript or jQuery?

My goal is to retrieve JSON data from the following URL: I have a button that triggers the function called "jsonplz()", which should display an alert message with the fetched JSON data. This is what my JavaScript code looks like: <script src="htt ...

Iterate through the complex array of nested objects and modify the values according to specified conditions

I am currently iterating through an array of objects and then delving into a deeply nested array of objects to search for a specific ID. Once the ID is found, I need to update the status to a particular value and return the entire updated array. Issue: Th ...

Can you explain the distinction between ()=>any and {():any} in Typescript?

There is no issue with this code now, and the Typescript compiler deems it completely valid. However, are these two type definitions truly identical? Can someone provide an explanation of the differences between them, along with some practical examples f ...

Property-based Angular Material row grouping in a mat-table is a powerful feature that enhances

Is there a way to organize the data in one row with the same ID? Currently, my data looks like this: Data Set: { "id": "700", "desc": "Tempo", "richiesta": "20220087", "dataElab": &quo ...

Retrieve JSON information from the driver's console using Selenium with Python

I am trying to retrieve JSON data from the console, which is shown in this image. Here are the codes I have used so far: j = driver.execute_script(" return document.getElementsByClassName('form-group text required assessment_questions_choices_text ...

I'm encountering an issue with the preflight request failing the access control check. It seems to be related to not having an HTTP ok status, and I've double-checked everything to make sure I imported

I've encountered an error message stating, "Response to preflight request doesn't pass access control check: It does not have HTTP ok status." Any suggestions on what might be causing this issue? Here is the backend code snippet: app.js app.del ...

What steps are involved in ensuring that this NodeJS package is compatible with browsers?

My latest pet project was built using nodejs, a technology I chose due to my lack of previous experience with it and my curiosity. Now, I'm looking to modify this package so it can run in a browser and eventually be published on Bower. The npm packag ...

Changing environment.ts with custom schematics in angular-cli

Currently, I am working on creating customized schematics for our Angular Cli project. One of the tasks involves adding properties/variables to both the environment.prod.ts and environment.dev.ts files. I am curious if anyone has experience with this and h ...

Is it necessary for JSON data to include formatted data?

When incorporating JSON data into a webpage section, there is often a requirement for special formatting to match the existing format on the page, which is performed serverside. This could involve formatting a number as currency, applying a specific date ...

Exploring the contents of a file in Rails

I'm currently facing an issue with a form that needs to read a JSON file for parsing and other actions. However, I am encountering difficulties in getting it to properly read within the controller. View: <%= form_tag({:controller => :admins, : ...

What is the best way to define the type of children for a React Native component in styled-components?

When I define a styled component like this: const Wrapper = styled(View)``; and attempt to use it while passing children to it, an error in TypeScript arises: The type '{ children: Element[]; }' does not have any properties in common with th ...

Setting the root path of an Angular2 application separate from the base URL in the HTML code

Currently, I am in the process of developing an angular2 application/widget that will be integrated into TYPO3 as a plugin and can be added to any content page. This means it may have varying root paths like: /page1/app /page/subpage/subpage/whatever TYP ...

Troubleshooting problem with handling Angular modules

I'm currently working on effectively organizing folders in my Angular application. Specifically, I've set up a /components directory for shared components and a /pages directory for page-specific components. Each directory has its own module but ...

Enhance SharePoint list items in Microsoft Graph with multi-choice field updates

How can I correctly update a multi-choice list item field using the Microsoft Graph in JSON? Multi choice fields return a json array of strings when queried: GET: /v1.0/sites/{siteId}/lists/{listId}/items/{itemId} "CAG_x0020_Process_x0020_Status": [ ...

Consolidate various arrays of objects while eliminating duplicate items based on an optional property

Imagine having multiple arrays like these: const arr1 = [ { "id": "1", "type": "sales" }, { "id": "2", "type": "finance" } ] const arr2 = [ { "type": "s ...

Challenge encountered when setting new values to an object depending on its existing values

I am facing an issue with a data object that stores values and their previous values. The keys for the previous values are suffixed with ":previous" e.g. foo and foo:previous. However, I encountered a type error when trying to assign values to the previous ...

Having trouble accessing information from content JSON using liquid within logic apps

I am currently working with a logic app that receives data from another logic app. So far, everything seems to be functioning properly as I can see data coming in the input (refer to the image below). https://i.sstatic.net/hed9G.png However, when I attemp ...