I am looking to combine multiple number values from different arrays in Typescript. My data model looks like this:
export class DataModel {
date : string;
number : any;
}
The main class contains an array of DataModels:
export class CountryData {
country: string;
province: string;
Long: any;
Lat: any;
dataset: DataModel[] = [];
}
Furthermore, I have an array of CountryData.
For example, two arrays of CountryData each containing three DataModel values:
let data: CountryData[];
let country1: new CountryData();
let country2: new CountryData();
let countrySum: new CountryData();
country1.dataset = [{'01/02/20',5}, {'01/03/20',10}, {'01/04/20',15}];
country2.dataset = [{'01/02/20',5}, {'01/03/20',10}, {'01/04/20',15}];
data.push(country1);
data.push(country2);
I want to loop through the data variable and get a result like this in the countrySum.dataset:
[{'01/02/20',10}, {'01/03/20',20}, {'01/04/20',30}];
This should be applicable to n arrays in data. Does anyone know how to achieve this using functions such as map, reduce, or others?
Thanks!