Reputation: 849
I have a array of in the following format.
timeSeries = [{ key: 'Time Series Data',
values: [ { 'label': '01/01', 'value': 20 } ] }];
now i have typescript object that has properties which i need to map to the label value and value value.
export interface Plot {
dateLabel: string;
x: number;
}
my plotArray is as follows
plotArray = [ { 'label': '01/03', 'value': 30 }, { 'label': '01/04', 'value': 40 }];
What are the different ways i could append my plotArray to values in the timeSeries in javascript?
Upvotes: 1
Views: 88
Reputation: 940
You can do that in many different ways such as:
Using concat
timeSeries.values = timeSeries.values.concat(plotArray);
Using lodash's concat function
timeSeries.values = _.concat(timeSeries.values, plotArray);
Using ES6 spread operator:
timeSeries.values = [...timeSeries.values, ...plotArray];
or
timeSeries.values.push(...plotArray);
Lastly you can iterate through the plotArray and push it one by one.
plotArray.forEach(function(plot) {
timeSeries.values.push(plot)
});
Upvotes: 6