score:2
Accepted answer
if your data is an array of objects, you can use reduce to get the sum:
data.reduce((accumulator, currentvalue) => accumulator + currentvalue.available_funds, 0)
score:0
try this:
componentdidmount() {
axios
.get('http://localhost:3000/api/bills/1')
.then(({ data }) => {
var sum = 0;
if(typeof data == 'object'){
data.foreach(funds => {
sum += parsefloat(funds.available_funds);
});
}
this.setstate({
availablefunds: sum,
isloading: false
});
})
.catch(err => {});
}
Source: stackoverflow.com
Related Query
- React display json key and value
- Sum field value in React from JSON API data
- Display a sum of value in json in React.js
- React Table : How do I total (sum) values to each of the holeOne thru holeNine and display the sum as a value in out: 41?
- React cannot display json - data is assigned a value but never used
- Display key and value pair from json In react js
- How to display nested json data in React in key and value pair form?
- What is default css display value for react web application?
- Display Animated Value in React Native Render Text Component
- Looping Json & Display in React Native
- how to display data in table using json in react js?
- Fix the last row of react material-table to display the sum of a particular column?
- Storing Value from JSON response to AsyncStorage React Native
- Updating React Json Value Conditionally
- How to fetch and display data from json file in react typscript
- How to display and handle dynamic checkoxes that are dependent on Task array value in the backend (Mongodb) in react js?
- How to display HTML received in JSON using React
- How to display JSON data inside render as table in React
- Load and display json data in react component
- React promise code need to change a json value
- How do I obtain a value from JSON object in a React render function?
- React - How do I display the first value of an array as the default value in a select form?
- Update just one value of JSON object and keep the old ones with React Flux
- Not able to set the JSON object of Arrays in React js using axios.get function and display the object of Arrays in table
- Click on radio button and display the corresponding value inside the radio button as selected in react js material UI design
- React on select change option value of display
- How to display images from a JSON URL array in React
- Display data json to table in react
- Display Json in react JS div formatted properly
- React - what is the right way to sum the value of object by its type and then setState
More Query from same tag
- React HOC with Router not finding page
- Change not able to update on commentsRef.on("child_changed", (data) => {
- How to set a test for multiple fetches with Promise.all using jest
- ReferenceError: _ref2 is not defined @ react-dom.production.min.js
- Getting TypeScript compile error when attempting prop drilling of state objects in Ionic/React
- How to setup jest with node_modules that use es6
- Toggle text within a variable type function in React JS
- Execute onClick immediately without getting error
- Creating styled url for finished react app
- How to use a dispatch (react-redux) into class Component
- useEffect has missing dependency
- How to loop in into multiple elements using single useRef?
- Cannot reach the cookies with Response.Cookies method in .net Core
- How to convert 2 object into single one
- How to bind the selected option from the drop down to a reactjs state property in functional component and show it to side of the dropdown
- Get item details react/redux hooks
- setTimeout in useEffect hook
- Gatsby GraphQL download multiple images at once
- React & Apollo, how to set authorization header when user logs in?
- Firebase onAuthStateChanged is being called twice upon login
- material-ui menu not close when dialog open
- How to override the default state parameters in redux reducers?
- Actions must be plain objects. Use custom middleware for async actions.how to solve this
- Returning null when accessing object properties in state?
- How to get rid of duplicates in React when using div contenteditable?
- cant map over and fetch the data present inside an array of objects
- React function uses outdated state
- Using React.lazy vs. webpack dynamic imports?
- i want to pass data from axios to an object in the state
- Using redux's useDispatch in a custom hook yields an error