Ways to extract data from an array containing nested objects

I have received data from an external source:

[{
  "mode": "CURR",
  "isin": "PLESLTN00010",
  "from": 451183,
  "to": null,
  "data": [{
    "t": 1624265539,
    "p": 5,
    "o": 5,
    "c": 5,
    "l": 5,
    "h": 5,
    "v": 2
  }]
}]

My goal is to extract the value of "c" within the data array.

This is what I attempted:

const arrNcnct = ncdata.map(a => a.data).flat();

Although it retrieves the entire data object, I'm struggling to specifically get the value of "c".

const c = arrNcnct.map(el => ({ current: el.c}));
console.log(Object.values(c));

The output shows:

[{"current": 5}]

Seems like I am missing something...

Answer №1

Here are the steps you can take:

let result = [{
  "mode":"CURR", "isin":"PLESLTN00010", "from":451183, "to":null,
  "data":[{"t":1624265539, "p":5, "o":5, "c":5, "l":5, "h":5, "v":2}]
}];
        
let nestedResult = result[0].data;

nestedResult is an array. If there is only one item in the array, you can access it by using nestedResult[0], but if there are multiple items, then a loop is needed.

To access the "c" property, use nestedResult[0].c

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

Is it possible to locate/create a JSON keyname in a jQuery $.post function?

Currently, I am diving back into the world of Ajax after a long break. At this point, I have created a page that is able to fetch a dynamic number of elements (initially ten, but this can change), and populates each of the ten divs with relevant text. In ...

Display refined outcomes on the search results page

In my app, the main feature is a search box on the homepage. Users can input their search queries and upon submission, they are redirected to a result page displaying the relevant results along with filtering options. The filtering functionality allows use ...

Within a single component, there are various types present when looping through an array containing objects

Hey there, I'm looking to iterate through an array containing objects with different types within a single component. operations = [ { "id": 15525205, "type": "mise_en_prep", & ...

NextJs manages the logic for processing requests both before and after they are handled

NextJs stands out from other frameworks due to its lack of support for filter chains, request pre-processing, and post-processing. Many node project developers or library creators may find these features essential for executing logic before and after API c ...

Is there an XML File Wrapper to Generate PDF Output?

Greetings Forum Members, I have been given the responsibility of creating a PDF file from multiple XML files. Has anyone come across an XML wrapper file before? This type of file would essentially contain a list of all the source XML file names in a spec ...

The perplexing results received when using the npm outdated command

Could someone provide an explanation for the meaning behind this output? $ npm --version 3.10.8 $ npm -g outdated npm Package Current Wanted Latest Location npm 3.10.8 4.0.2 3.10.9 As stated in the documentation, the "Wanted" column should d ...

The customized Vaadin component with a tag is missing from the MainView layout

I am attempting to integrate my custom vis component into the MainView VerticalLayout. However, it is appearing above the layout and the layout itself contains an empty component tag. Custom component code In this section, I have labeled my component as " ...

When converting a Hebrew Excel sheet to JSON, question marks are generated in the output

Currently, I am facing an issue while trying to convert Excel (*.xlsx) to a JSON object in Node JS. The problem is that all the columns containing Hebrew characters end up getting converted into question marks. To illustrate the issue: https://i.sstatic. ...

How can I display a list from an array by clicking a button or calling a function?

After incorporating a button that generates an unordered list from an array (e.g. var list_content = ["Apple", "Banana", "Orange", "Mango", "Papaya"];), each item of the array is displayed as a list item through the li element. The resulting list is append ...

How can Vue FullCalendar be configured dynamically?

I am trying to dynamically change some options in Vue FullCalendar, but the calendar is not applying them. You can check out my example here. The button at the bottom should set the maxTime option from 20:00 to 18:00. Is there a way to refresh the calen ...

Locating the matching value in the <select> element and showcasing it

I'm trying to create a function where selecting an option from one dropdown menu will display the corresponding value in another column. For instance, if someone chooses "3" from the first dropdown, the value displayed in the third column should be "3 ...

JavaScript alerts

Can anyone recommend a quality library with beautifully animated popups? Specifically, I need a popup that allows for basic HTML fields such as text areas and more.... I am in search of a popup that will overlay on the current page, rather than opening a ...

Retrieve a JSON object from a JSON array using a specific key

I am facing a situation where I have a json array containing multiple json objects. Let's take the example of a course object with the following structure: {"name": "Math", "unit": "3"} The json array looks something like this: [{"name": "Math", "u ...

A step-by-step guide on generating orders and order line items in Odoo with the help of Node.js

Struggling to create orders and add order-lines to the odoo database? Getting stuck with an error message faultString: ('The requested operation ("create" on "Sales Order" (sale.order)) was rejected because of the following rules:\\n\&b ...

Step-by-step guide on Setting up the bronto.sca.cart object using Bronto JSON

I have implemented the Bronto Tag Manager to track cart details successfully. After including the Bronto Commerce JavaScript snippet on my page, I am now able to create the bronto.sca object. While bronto.sca.config() and bronto.sca.id are returning valu ...

Choosing a particular option will reset a different selection box based on the selection

One's selection of city and building depends on the choice made for the state by the user. <form method="post"> <div class="summary"> <div class="trip"> <select name="State" class="state"> <option select ...

Struggling with the process of transferring an array to a mySQL table

Today I decided to tackle using phpMyAdmin and MySQL, but I'm struggling with sending an array to a table through a for loop. The variable $tid changes with each transaction, while $wineFirstNames and $wineLastNames are both arrays. for(i = 1; i < ...

Using Javascript to Pass Variables to Ajax with getElementById

Struggling to figure out how to effectively pass a Javascript Variable to Ajax and then post it to PHP? While both the Javascript and PHP code are functioning as expected, the challenge lies in transferring the Javascript Variable to Ajax for subsequent ...

Arrange the columns in the Table in both ascending and descending order

While working on my React and MUI Table project, I encountered an issue with implementing sorting functionality for each column in both ascending and descending order. Whenever I click on the header to sort a column, an error message saying "Data is not it ...

Just starting out with jQuery: seeking advice on a user-friendly slideshow plugin, any tips on troubleshooting?

I am currently trying to incorporate a basic jquery slideshow plugin, but I seem to be encountering some difficulties. The documentation mentions the need to install 'grunt' and 'node dependencies', which is confusing to me as I am new ...