There are, for example, several objects in the array:
let shop = [{ id: 105, date: '2018-10-11', fact: 100, plan: 95 }, { id:105, date: '2018-10-12', fact: 105, plan: 100 }, { id:106, date: '2018-10-11', fact: 110, plan: 115 }, { id:106, date: '2018-10-12', fact: 120, plan: 115 }]; It is necessary to obtain a structure from objects with id and arrays of fact and plan (sales, for example):
let groups = [{ id: 105, fact: [100, 105], plan : [95, 100] }, { id: 106, fact: [110, 120], plan: [115, 115] }]; console.log(groups); I tried to use reduce , but then I add up all the facts and plans without considering id. I ran the first array in forEach and map , but I also can't figure out how to leave id unique, and merge fact and plan into arrays to these id.