I have an Object of Arrays like this and I want to combine them(add values to every key )
It's possible to give to every array key: "state" and value: parseFloat(value) or how i can do it?
I have an Object of Arrays like this and I want to combine them(add values to every key )
It's possible to give to every array key: "state" and value: parseFloat(value) or how i can do it?
You can save yourself some typing, and provide some future-proofing in case you later need to handle a different set of territories, by getting the keys from the object itself, and then iterating over those keys:
let val = {};
val = filteredMiles.reduce(
function (previousValue, currentValue) {
const keys=Object.keys(previousValue);
const result={};
keys.forEach(key=>{
result[key]= parseFloat(previousValue[key]))
+parseFloat(currentvalue[key])
})
return result
};
});
console.log(val);