I have below object and i need counts from the byPerson array inside the object. Basically, i want to check the count in each byPerson array elements and get those properties as an array.
for e.g.
var Closed = [16, 0, 1, 43] // here 1st count object has 16 as closed, 2nd count object has no closed property (so we set it to 0), 3rd one has value 1 and 4th one has value 43
Similarly var Verify = [0, 5, 0, 1]
How can i achieve this calculation and stored the results in Closed and Verify variables as shown above.
{
"byPerson": [
{
"personId": "1514903899",
"firstName": "Yatish",
"lastName": "Patel",
"count": {
"Closed": 16,
}
},
{
"personId": "1559363884",
"firstName": "Samuel",
"lastName": "Chacko",
"count": {
"Verify": 5
}
},
{
"personId": "297895805",
"firstName": "Tim",
"lastName": "Altman",
"count": {
"Closed": 1
}
},
{
"personId": "others",
"firstName": "Others",
"lastName": "",
"count": {
"Closed": 43,
"Verify": 1
}
}
],
"resultDateTime": "2021-04-23T12:14:33.901"
}
I tried this way
const closedValues= releaseData.byPerson.map(element => element.count["Closed"] === undefined ? 0: element.count["Closed"]);
const verifyValues= releaseData.byPerson.map(element => element.count["Verify"] === undefined ? 0: element.count["Verify"]);
```
But i guess it is not the optimal solution where i have to calculate for each one seperately.