transform JSON structure into an array

Is it possible to convert an interface class and JSON file into a list or array in order to work on it? For example, extracting the Racename from each object in the JSON file and storing it in a list/array. Here is the interface structure:

interface IRunners{
Racename: string;
Category:number; 
Gender:string; 
Work:string; 
FullName:string; 
Rank:number;
Point:number;
Numparticipant:number;
rankparticipant:number;
precentagePart:string; 
NumRaces:number; 
RaceTime:string; 
rankCat:number; 
PointCat:number; 
RaceDate:string;
}

This is the content of the JSON file (Runners.json):

[
  {"Racename":"A1","Category":34,"Gender":"זכר","Work":"AMDOCS","FullName":"Simon Work ","Rank":1,"Ponit":1,"Numparticipant":0,"rankparticipant":0,"precentagePart":"0","NumRaces":1,"RaceTime":"2018-10-18T00:34:20","rankCat":1,"PointCat":1,"RaceDate":"2018-10-05"}
] 

The subscription process looks like this:

  this.runnerService.getRunners().subscribe(
        runners=>{
          this.runners = runners;
          this.filteredCompetitions = this.runners;
          this.filteredRunners = this.runners;
        }

I want to transform the JSON data stored in runners into an array so that I can manipulate it and extract necessary information. As a newcomer to Typescript and Angular, I may be making some mistakes.

Answer №1

If you want to extract specific data from a JSON file, you can utilize the Array#map() method.

// Assuming that runners.json is stored in the same directory as this script
const jsonArray = require("./runners.json")

// Extracts an array of race names and stores them in listOfRacenames
const listOfRacenames = jsonArray.map(data => data.Racename)

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

Ensuring Consistent Item Widths in a Loop using JavaScript or jQuery

In my code, I created a function that dynamically adjusts the width of elements in a loop to match the widest element among them. // Function: Match width var _so20170704_match_width = function( item ) { var max_item_width = 0; item.each(function ...

What is the best way to enable ondemand icon usage in Vue Vite 3 with Iconify?

Did you know in the iconify documentation, there is just one simple step to follow? Visit All you have to do is: npm install --save-dev @iconify/vue import { Icon } from '@iconify/vue'; <Icon icon="mdi-light:home" /> After thi ...

Resetting the selected options in AngularJS dropdown lists

Utilizing ng-repeat in my HTML code to iterate over a JavaScript array and displaying it within a selection. I am trying to achieve the functionality of clearing all selected data from these dropdown lists when a button is clicked. Snippet of HTML: <d ...

Error came up as "backbone.radio.js" and it threw Uncaught SyntaxError since the token import appeared unexpectedly

I've been struggling to transition an application from Backbone to Marionette (v3) for the past two days. Every time I try to run the app in the browser, I keep encountering this error in the console (resulting in a blank screen): Uncaught SyntaxErr ...

Enhance visual content using JavaScript to filter images in React

I am currently developing a React app with multiple pages that are being imported into another component page. The structure of one of my pages looks like this: export default class Product1 extends React.Component { render() { return ( <di ...

Is your dropdown menu malfunctioning with jQuery? (Chromium)

I am currently working on a website that requires the options in the second dropdown menu to change based on the selection made in the first dropdown menu. However, despite the fact that the browser is recognizing the javascript file, it doesn't seem ...

Problem encountered when using the Mongoose find() method with the exec() function

Could you please clarify why the code snippet below is returning audiences instead of an empty array? return Audience.find() .exec((err, audiences) => { if (err) return errorHandler.handle('audienceService', err); return Promise.re ...

Using jQuery to load the center HTML element

So here's the plan: I wanted to create a simple static website with responsive images that load based on the browser width. I followed some suggestions from this link, but unfortunately, it didn't work for me. I tried all the answers and even a ...

An issue arises when trying to group and sum an array of objects due to difficulty converting strings to arrays in TypeScript

Below is the provided code snippet: Definition of Interface - interface IWEXInterface { readonly Date?: string; "Exec Qty"?: string; readonly Expiry?: string; } Data Collection - let data: IWEXInterface[] = [ { Date: &qu ...

What's the best approach for revalidating data with mutate in SWR?

Whenever a new album is created in my app, the post request response includes an updated list of all albums. To enhance the user experience, I wanted the newly created content to automatically show up without requiring a page refresh. Although I am famil ...

Personalize JSON Output

Currently, I am working on incorporating jqvmap into my project. The original format of my json response is as follows: [ { "Count": 10, "ProvinceCode": 34 }, { "Count": 6, "ProvinceCode": 59 } The required format for jqvmaps is as shown ...

Verify whether the user's email is registered in the database

I have a login form and I want to verify if a user's email exists in the database, but I'm not sure about the syntax for integrating Angular with Node. In my Main.js file, I have an ng-click on the submit button that triggers this function. I ex ...

Adjust the stacking order of bars in a vertical chart and exclude negative values with Vega-Lite

I am utilizing this chart as a guide for my current project Explore Vega Editor here Is there a way to rearrange the order of the 'Measure' while keeping 'Measure 1' at the top, disregarding its negative value? I want to display the & ...

Utilizing the power of Node.js with Oracle seamlessly, without the need for the Oracle Instant

Currently, I am working on testing the connectivity to our Oracle databases. Recently, I came across node-oracledb, a tool released by Oracle that aims to simplify this process. However, one major hurdle is the requirement of having the Oracle Instant Clie ...

Display all elements with a blank attribute using jQuery

I'm currently dealing with a list containing multiple hidden list items: <ul> <li rel=""> </li> ... </ul> My goal is to display only those list items that have an empty string as the value of the attribute rel. D ...

retrieving JSON data using ajax and processing it in PHP

I have some data that needs to be sent to the backend, and it looks like this: function view(){ let id = "12345678"; let profile = [{name:"dave", department : "Engineering"}, {name:"Tedd", ...

What steps can I take to resolve the CLIENT_MISSING_INTENTS issue?

After diving into learning about discord.js, I've run into a bit of a roadblock. Despite trying to troubleshoot by searching online, I can't seem to resolve the issue. const Discord = require('discord.js'); // const Discord = require(&a ...

eliminate the firebase firestore query using onSnapshot

Seeking assistance with the following code snippet: firebase.firestore() .collection("chatrooms") .doc(`${chatId}`) .collection(`${chatId}`) .orderBy("timestamp") .limit(50).onSnapshot((snapshot) => { //performing oper ...

Keep elements in position when their bottom edge becomes visible while scrolling

This task may appear intricate, but I will do my best to explain it! I want to create a continuous scrolling article display similar to Bloomberg Politics (), but with a slight twist. My idea is to have the current article's bottom edge stick to the ...

CSS style takes precedence over inline JavaScript transitions occurring from a negative position

I am puzzled by a JavaScript fiddle I created which contains two small boxes inside a larger box. Upon clicking either of the buttons labeled "Run B" or "Run C", the corresponding box undergoes a CSS transition that is controlled by JavaScript. Below is t ...