I’ve got a JSON data set like so:
{ "ts": "4", "FlowvolMeas_dL_12_hr": "3612.82", "FlowvolUnexp_dL_12_hr": "40.26" },
{ "ts": "5", "FlowvolMeas_dL_12_hr": "237.15", "FlowvolUnexp_dL_12_hr": "0.98" },
{ "ts": "6", "FlowvolMeas_dL_12_hr": "12.04", "FlowvolUnexp_dL_12_hr": "0.2" },
and another like so:
{ "ts": "4", "FlowvolMeas_dL_30_min": "12", "FlowvolUnexp_dL_12_hr": "2" },
{ "ts": "5", "FlowvolMeas_dL_30_min": "22", "FlowvolUnexp_dL_12_hr": "3" },
{ "ts": "6", "FlowvolMeas_dL_30_min": "33", "FlowvolUnexp_dL_12_hr": "4" }, ...
What I hoping to do is do a sort of global addition of two fields without needing to individually define each case, i.e. 30_min
and 12_hr
.
Some sort of loop I am thinking of that when I encounter anything with a prefix of FlowvolMeas
and FlowvolUnexp
, I add the two values together and append the total to the end of that same record.
Something like a wildcard search, perhaps? Whatever the JavaScript equivalent of total = FlowvolMeas* + FlowvolUnexp*
would be, followed by appending that new key-value pair to the end of the record.