'Typescript map utilisation
this is the data that I have :
and I've created 4 arrays respectevly
public underlyingsFirstRow = [{perf:0,color:''}];
public underlyingsSecRow = [{ perf: 0, color: '' }];
public underlyingsThirdRow = [{ perf: 0, color: '' }];
public underlyingsFourthRow = [{ perf: 0, color: '' }];
I want the underLyingsFirstRow to contain the first element of each of the arrays
ex [1.09,1.44,0.72,0.98,....,1.22]
and for the underlyingsSecRow
[0.96,1.40,0,0.93,0,0.99,...,1.09]
since the third and fifth and the seventeenth data row has only one element and it's 0.72
I want the underlyingsSecRow to have a value of 0 indicating that there is no value there so I can use it to display some points in a graph
and I want to do the same for the remaining array that I've created
this is what've wrote
this.underlyingsFirstRow.shift();
this.underlyingsSecRow.shift();
this.underlyingsThirdRow.shift();
this.underlyingsFourthRow.shift();
this.products.map(p => p.Underlyings.map((u, index,array) => {
if (index == 0) {
this.underlyingsFirstRow.push({ perf: (Number((u.perf100 * 100).toFixed(2))), color: u.colorPerf });
} else if (index == 1) {
console.log()
if (p.Underlyings.length > 1)
this.underlyingsSecRow.push({ perf: (Number((u.perf100 * 100).toFixed(2))), color: u.colorPerf });
else {
this.underlyingsSecRow.push({ perf: 0, color:'white' });
}
}
else if (index == 2) {
this.underlyingsThirdRow.push({ perf: (Number((u.perf100 * 100).toFixed(2))), color: u.colorPerf });
}
else if (index == 3) {
this.underlyingsFourthRow.push({ perf: (Number((u.perf100 * 100).toFixed(2))), color: u.colorPerf });
}
}));
for the first array it worked since they all have at least one element

but for the others it didn't work and the length of the array got reduced ex this is underlyingsSecRow
is there a way to get the desired data ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


