I'm trying to set default value for all my NULL objects.
Here's what I have
private setDisplayAmount(summaries: summary[]): void {
summaries.map(t => {
// do some magic, and then...
this.setDefaultValueForEmptyAmounts(t);
});
}
private setDefaultValueForEmptyAmounts(summary: Summary): void {
Object.values(summary.displayAmounts).map(property => property || 0);
}
I've no idea why setDefaultValueForEmptyAmounts doesn't work properly...
This will work but is less esthetic:
private setDisplayAmount(summaries: summary[]): void {
summaries.map(t => {
// do some magic, and then...
t.displayAmounts = {
OneAmount: t.oneAmt || 0,
TwoAmount: t.twoAmt || 0,
// ... for all properties
};
});
}
maps toforEaches, and instead of doingObject.values().map(), you wantObject.keys(x).forEach(k => x[k] = ...). Or just use for loops, if you don't understand how these functional programming methods work.