Input:
[ { 15: "3.0", 20: "6.0", 34: "4.0, Dosis: "First", Sex: "Male" }, { 15: "3.0", 27: "6.0", 32: "4.0, Dosis: "Second", Sex: "Male" }, { 15: "", 23: "12.0", 44: "7.0, Dosis: "First", Sex: "Female" }, { 15: "3.0", 70: "6.0", 54: "34.0, Dosis: "Second", Sex: "Female" }, ] I am trying to reordening some data, because I need to do a Pie Chart in JavaScript.
I did something but going through many processes and maybe there is a better way to do this
This is my actual data (similar):
I need just the totals of the whole data per dosis and sex. I also need to change the "string number" to number.
Expected Output:
[ { totalFirstMale: 13 Dosis: "First", Sex: "Male" }, { totalSecondMale: 13 Dosis: "Second", Sex: "Male" }, { totalFirstFemale: 19 Dosis: "First", Sex: "Female" }, { totalSecondFemale: 43 Dosis: "Second", Sex: "Female" }, ] PD: The object key value means the age, but I just need the total per sex.
The original array contains 4 key sex (male, female, unknown, intersex) with same structure.
I would really appreciate your help!
https://stackoverflow.com/questions/66501746/how-can-i-get-totals-from-array-of-objects-with-string-values March 06, 2021 at 10:17AM
没有评论:
发表评论