What methods can be utilized to effectively showcase and modify exclusively the keys within a nested JSON structure?

I am working with a JSON structure that looks like the image linked below. I want to extract and rename only the yellow highlighted keys, then store them in a new array.

Here are the key renaming requirements:

act = Actual

prognosis = Prog

plan = Planning

Can you provide an example of how I can efficiently execute this plan?

Answer №1

It's a bit unclear what you're looking for exactly, but if the structure remains the same, you could try something like this

let result: string[] = [];

const nameMap = {
  act: 'Actual',
  plan: 'Planning',
  prognosis: 'Prog'
};

Object.keys(actAndPlanBalance).forEach(x => {
  if (actAndPlanBalance[x]['act']) result.push(nameMap.act);
  else if(actAndPlanBalance[x]['plan']) result.push(nameMap.plan);
  else if(actAndPlanBalance[x]['prognosis']) result.push(nameMap.prognosis);
});

Playground example.

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

Node.js VAR DeclarationIn the world of Node.js, we make

I am currently expanding my knowledge on Node.js. I came across a line in my book that has sparked my curiosity, and I wanted to seek some clarification. The specific line in question is: var user = req.user = users[req.params.name]; After doing some re ...

`Inability of ngmodel to bind integer values on select element`

From the service, I will be receiving an integer as the selected value and need to send it back as an integer. Please refer to the code in this Plnkr link. <!-- Working --> <div ng-init="selectedvalue = '3'"> <select ng-model= ...

Vercel does not support Angular-router

I am currently working on deploying my serverless web MEAN application using Vercel. I have encountered an issue where accessing a route through the navigation menu works fine, but when trying to access the same route directly via http://vercel-dev/some- ...

Turning a multi-row table header into div elements using Javascript

Does anyone have a JavaScript algorithm that can analyze a table header and then output the equivalent DIV elements as either a string or object of DOM? The table header has the following structure: Here is an example of the HTML: <thead> <t ...

The Transition Division Is Malfunctioning

I've encountered an issue where I am trying to move a div by adjusting its left property, but no transition is taking place. Regardless of the changes I make to my code, the result remains the same. Below is the current state of the code. Can anyone i ...

Looking to adjust a group of range sliders. Can you help me troubleshoot my code on jsfiddle

I am looking for a way to ensure that my three range sliders all draw from a shared "value pool." For example, if the maximum value is 100 and slider-1 is set to 51, then sliders 2 and 3 should share the remaining value of 49. Currently, when slider 1 is a ...

Ways to evenly disperse values

I have a total of 10,000 units that I want to distribute among 99 points in a non-uniform manner following an increasing linear curve. The value assigned to each point will progressively increase from the first point to the last, where the final point migh ...

Assigning Dictionary Values to a Variable

I am working with a DropDownList and have a requirement to store values in a javascript variable before setting it on the DropDown. I need to loop through the values and format them as shown below: var categories = [{ "value": 1, ...

The propagation of SVG events from embedded images via the <image> elements

I'm currently developing a diagramming tool using HTML, CSS, and Javascript with SVG for the drawing canvas. This tool consists of predefined "building blocks" that users can place on the canvas, rather than allowing free-hand drawing of shapes. Each ...

What is the best way to iterate over an indexed attribute in PHP?

Here is my ajax code snippet: $.ajax({ type: "POST", url: "bee_sesi_edit.php", data: 'serv_ruang='+ serv_ruangx +'&who='+names +'&sesi_d1='+ sesi_d1 +&apos ...

Analyzing atypical information (chess statistics) within a table's column

I have been working on a function to extract data from a chess website and store it in a dataframe. The code I have so far almost completes the task, but there are some issues. import chessdotcom import pandas as pd import regex as re import json from io i ...

Tips for correctly retrieving an element from an array in Angular 5 using JSON data

I've defined a JSON structure as follows: export class Company { name: string; trips : Trip[] = []; } Although I can log the entire 'company' object in the console using: console.log(this.company); I am having trouble accessing the i ...

Having trouble adding space between paragraphs inside a div element while trying to retrieve its content using jQuery

Issue Description: Currently, I am utilizing the jQuery syntax below to count words: var value = $('#displayContent').text(); Before counting the words, I aim to employ a RegExp in value that concatenates the last word of each sentence with th ...

The form's onsubmit function, which triggers an ajax call, does not complete before the form proceeds to its next action. Interestingly, this issue is only experienced on

In my Django application, I am developing a feature that allows users to create rubrics for grading assignments. Each rubric item can be edited, and upon form submission, the system checks if any rubric items have been modified. If changes are detected, th ...

Real-time Property Availability Widget

I need assistance with creating a website for a homeowner who wants to rent out their property. The client requires a feature that allows them to log in and easily mark individual days as available or unavailable for rental by choosing specific colors for ...

Expanding Soccer Field to Maximize Viewing Experience- React/CSS

I'm looking to make a soccer pitch design in CSS that can adjust its size based on the device screen, making it responsive and reusable for both web and native app development (specifically with React). Currently, I'm stuck trying to determine h ...

Unable to install the most recent version of Angular CLI

As I embarked on a new project using Angular, it became clear that I needed to update my global packages. Running Windows10, the ng -v command displayed the following: Angular CLI: 6.0.8 Node: 8.12.0 OS: win32 x64 Upon further investigation, I discovere ...

Node.js server side rendering encounters import file failure

In my current project, I am working on implementing server side rendering with React using TypeScript. All of the components, containers, and other directories are located within the src directory. When React imports a file from a location such as ./src/p ...

Adjust picture based on the MaterialUI slider's value

I want to incorporate a discrete Slider component from Material UI into my React web app. The goal is to have the user change a picture every time they adjust the slider value, with the new image displayed in a specific div. I am wondering how I can achiev ...

Ways to extract the body/message of a request from an HttpErrorResponse in Angular using the ErrorHandler

Imagine I make a request to the server using the post method in order to create a new user. In case the server responds with an error, my goal is to retrieve the form data that was submitted along with that request from the ErrorHandler. This information i ...