I am iterating trough objects which could have same key, for exapmle:
let data = {};
// object 1
metadata:{
datefrom: '2001'
}
// objeft 2
metadata:{
dateto: '2002'
}
So when iterating they have same variable name objDataEl .
I am trying to assign them to the data object, but the problem is that only the last one gets assigned.
I've tried doing this:
data = Object.assign(data, objDataEl);
and
// strDataKey is = 'metadata'
data[strDataKey] = objDataEl;
But in both cases it got overwritten and only the last value was inserted into object.
After itteration it should look like this:
data: {
metadata: {
datefrom: '2001',
dateto: '2002'
}
}
Data structure looks like this:
data = [ { "metadata" : { "datefrom" : 2001 } }, { "metadata" : { "dateto" : 2015 } } ];
How can this be accomplished ?