score:1
Accepted answer
it is worth adding some more data, but here you go.
let rawdata = [
{
"clicks": {
"2019-01": [
{
"clicks": "47",
"id": 63,
"type": 0,
"user": 5
},
{
"clicks": "459",
"id": 5,
"type": 0,
"user": 5
}
],
"2019-02": [
{
"clicks": "0",
"id": 44,
"type": 0,
"user": 12
}
]
}
}
];
const mymonthlyclickcount = (record) => {
if(array.isarray(record) === false) record = [record];
return record.map(year => {
let arrmonth = [];
for(mth in year.clicks) {
let m = {
month: mth,
clicks: year.clicks[mth].reduce((a,v) => a+=parseint(v.clicks),0)
};
arrmonth.push(m);
}
return arrmonth;
});
};
console.log(mymonthlyclickcount(rawdata));
console.log(mymonthlyclickcount(rawdata[0]));
Source: stackoverflow.com
Related Query
- Dynamically created array length in reactJS
- Material UI Texboxes Dynamically created form Array Disply in multi columns ReactJs
- Can React.createRef() be created dynamically from an array of state objects?
- How to find length of an array of objects from ReactJS setState?
- Unable to map through dynamically created array through redux
- ReactJs pass props dynamically from array
- How to dynamically modify the values inside an array according to a length of a string?
- dynamically slice array of product data to display in ReactJs component
- Dynamically rendering form elements and saving them in an array in ReactJS
- Dynamically rendering values in a reactjs array map
- How to get values from dynamically created inputs with ReactJS
- ReactJS dynamically add key to array of mixed content
- How to display array of objects in table getting dynamically from backend in ReactJS
- Error dynamically updating an array list in ReactJs
- Getting the length of an array of objects in Reactjs
- ReactJS Object.keys().length returning number of values rather than length of array of keys
- how to change only the color of the chip clicked in react from a dynamically created array of chips
- ReactJS get values of dynamically created Radio Buttons and pass them into state (usestate)
- Problem accessing data of an array created from the state in Reactjs
- How to dynamically add and remove mapped array to another array when clicked and remove from arr when clicked again in reactjs
- Nodejs/MongoDB: Push dynamically created object into array
- Dynamically store api response in a new array in reactjs
- Dynamically created array by html objects - asynchronous
- passings array as props in reactjs
- Render Content Dynamically from an array map function in React Native
- Dynamically Loading Local Images with ReactJS
- React.PropTypes array with specific length
- ReactJS - setState of Object key in Array
- ReactJS : What is the best way to give keys in array element
- ReactJS with Material-UI: How to sort an array of Material-UI's <TableRow> alphabetically?
More Query from same tag
- Parsing error: Unexpected keyword 'export'
- 400, message: "No search query" in Spotify API
- Cannot use ant layout slider collapsable with SSR with NextJs
- Why does Route with children as components cause Typeerror, but route with component does not?
- Import CSS in a react app
- Nextjs build failing because of jsonwebtoken in _middleware.ts
- How to update object state using useState hook
- How to display fetched array of objects and save multiple fetched arrays to state?
- Track Color in input type Range in react
- React dropdown issue
- React + Redux for a complex SaaS
- Map function not able to implement in reactJS app
- ReactJS change color of the selected option in a select option control
- how to avoid overwriting when inserting todolist task list
- Render multiple containers in react js
- How do I use Jest to test a React view wired to store?
- React selecting option with object as attribute value
- How can I render different news components into the Navbar Component & display their data on the Navbar page, On Click of Navbar menu links
- React: How can I watch for property changes of my UseRef variable (UseEffect doesn't work)
- 'TypeError: illegal operation attempted on a revoked proxy' when using Immer with setState
- importing image with es6 import or require during runtime
- Render HTML tag based on a prop in Typescript
- ESLint no-use-before-define
- Why is this.props undefined in my ReactJS code?
- How to change Uploading text in upload component in antd?
- How to render a component only for one Route?
- Properly returning nested state with Object.assign
- React-Select - clickable values with custom handler
- How do I make all the contents of a Grid item stretch to the bottom, minus the typography?
- react input field not updating useState with onClick event