arr = [{
data: [1, 2, 3, 4, 5, 6],
name: "object 1"
},{
data: [7, 8, 9, 10, 11, 12],
name: "object 2"
}
]
newArr = [{
jan : 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
name: "object 1"
},{
jan : 7,
feb: 8,
mar: 9,
apr: 10,
may: 11,
jun: 12,
name: "object 2"
}]
const months = Array.from({ length: 12 }, (n, i) => {
return new Date(0, i).toLocaleString('en', { month: 'short' }).toLowerCase();
});
const newArr = arr.map(({ data, ...item }) => (
data.forEach((n, i) => item[months[i]] = n),
item
));