Total noob question. In PHP I can easily do this:
foreach( $array1 as $key => $value ) {
$array2[$key] += $value;
}
I cannot figure out a way to do this in javascript... I'm sure there must be a way.
EDIT: It doesn't really matter what I loop over, there should be a generic solution for creating an associative array or object on the fly inside a loop and also dynamically create it's key/value pairs with the option to add up numbers. Maybe the following piece of code will help to understand:
var vat = {};
InvoiceItems.each(function(item){
vat_rate = item.get('vat_rate');
vatsum = Number(roundNumber( 100 * item.get('vat'), 2 ) / 100, 2);
vat[vat_rate] += vatsum;
});
The problem is, this results in an object like this: {"20": "undefined18.00","null":"0.00"}
So there's the "undefined" and also an empty null key/value pair.