Hi I have the following object I am reducing to the key that its value is the greatest:
project.approved_account_ids: {
"sp02.testnet": 3,
"sp03.testnet": 1
}
Like so..
<Typography variant="body2">
Architect: {Object.keys(project.approved_account_ids).reduce((a, b) => project.approved_account_ids[a] > project.approved_account_ids[b] ? a : b)}
</Typography>}
But if the object is like
project.approved_account_ids: {}
I get the error - TypeError: Reduce of empty array with no initial value. Which I know it is because there is not always keys and values to reduce.
I tried adding an initial value at the end like
{Object.keys(project.approved_account_ids).reduce((a, b) => project.approved_account_ids[a] > project.approved_account_ids[b], 0 ? a : b)}
But that doesn't work. What would be the best method to check if there are values in the first place before applying reduce()? Any help would be appreciated!!