score:2
Accepted answer
you can use array.reduce
to count this in one go:
const data = {
"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"
}
const result = data.byperson.reduce((result, {
count
}) => {
result.closed.push(count.closed || 0);
result.verify.push(count.verify || 0);
return result;
}, {
closed: [],
verify: []
});
console.log(result);
Source: stackoverflow.com
Related Query
- Loop through array of object and get values
- Loop through Array of object with the same data on some object and get it displayed once
- How to loop through an array of objects and get specific key values in React?
- Loop through object and get random item in javascript
- Loop through array of objects, check for a matching parameter and add the matching object to new array
- Loop through array of objects and return object keys
- How to loop through an array with keys and values in to send a request for Axios.get's params in ReactJS?
- how to loop through data and assign values to state array in react
- Can we loop through event.target and get attribute values for each element inside a form
- loop through the status object and change the values
- How to loop through new input boxes renderer in React and get the values in an array?
- How can i get values from multiple input boxes on form submit and store the values as an object in an state array for React?
- react js filter through an array of objects and compare values within to get the closest value to a variable
- How loop through an object array and showcase separate HTML elements one by one
- ReactJS How to loop through an array and fetch specific attribute of Object inside another array
- How to loop through an array and display data within the object of that array, in react and javascript
- How to map through an Array of object with the same data on some object and get it displayed once and also get other properties
- for of loop unable to loop through values of an object which has been treated as an array in reactjs
- How to loop through an object with key and associated array and filter the array based on value presence in another array
- Loop through Object which has Array as value and create div for each key with its value as information
- Loop through specific array of object and assign to new object
- mapping through array of objects and accessing object values
- Fetched data from external api,how to loop through the array and display values
- Finding an object in array and taking values from that to present in a select list
- React.js iterate through object keys and values using map
- how to get key and value of object whose values are not equal to null?
- Loop through array of file urls and download each one with React
- Loop through array and render multiple instances of a child component with that data with React?
- How do i iterate over an array of object in react.js and add the values of prices in the object as shown below
- React - How to loop and update values in object model?
More Query from same tag
- Change state of a parent's component using child component?
- Cannot read property 'handleChange' of undefined
- cannont send message through renderer process in electron
- Relay Modern: delete record in optimisticUpdater
- Warning: A component is changing an uncontrolled input to be controlled
- Props not being passed to React component
- How to trigger redux action in react componentDidUpdate method?
- React: avoid unnecessary re-renders of child components (with callback prop) when parent re-render too often
- Use data from an array as src path for an img
- Prevent all children re-rendering every call of setState
- React-bootstrap tooltip not firing
- Cannot seem to change props of component
- useState Hook with JSX
- Typescript + React call parent method from child component
- Jest snapshots not working with some Semantic-UI-React components
- DraftJS Uncaught TypeError: Cannot read property 'blocks' of undefined
- Using a single component multiple times in a single parent class in react.js
- Convert string to React JSX
- React-router-dom protected route w/ async
- How to access value passed to {children} in React functional components with no "concrete" child element?
- what happens in React hooks when executing some function after settingSomeState() function in parents function
- Editable field in a table in reactjs
- {detail: 'CSRF Failed: CSRF token missing.'} Django and React
- React: mapping array of objects with nested arrays
- Using CSS Modules and 3rd party packages
- Print from multiple text type inputs in React page
- React app deployed on heroku but api call doesn't work
- React app does not render inside Facebook instant game iframe
- Getting bugs in Routing in React
- Images are mobile responsive but are not responsive on Desktop