There is an array in which there are objects with an array of data.
You need to get the sum of all elements of the array of objects and add each sum to the object, then you need to get the sum of two objects and also add to the object.
You also need to add the elements from the array of the first object with the elements from the array of the second email and add them to the array with the sum of each property, i.e. a) [1,2,3] and object b) [4,5,6] and add them get the output [5,7,9]
I was able to get the sum of two elements of the array, but the variant turned out to be very wooden, because it is tied to the property of the first object
function chartSumm(arr) { let obj, firstArr = [], lastArr = [], sumArray = [] arr.forEach(function(item, index) { for (let el in item.data) { if (item.label === 'ΠΠΊΠΊΠΎΠ½ΠΎΠΌΠΈΡ Π½Π° Π°Π½Π½ΡΠ»ΡΡΠΈΠΈ') { firstArr = item.data; } else { lastArr = item.data } } }); let firstObjSum = firstArr.reduce(function(prev, curr, index) { return prev + curr }); let twoObjSum = lastArr.reduce(function(prev, curr, index) { return prev + curr }); obj = { 'Π¦Π΅Π½Π° Ρ ΡΡΠΎΠΉΠΊΠΈ': firstObjSum, 'ΠΠ½Π½ΡΠ»ΡΡΠΈΡ Π±Π΅Π· ΡΡΡΠ°ΡΠ°': twoObjSum, 'ΠΠ±ΡΠ°Ρ ΡΠΊΠΎΠ½ΠΎΠΌΠΈΡ': firstObjSum + twoObjSum }; console.log(obj) } chartSumm([{ label: 'ΠΠΊΠΊΠΎΠ½ΠΎΠΌΠΈΡ Π½Π° Π°Π½Π½ΡΠ»ΡΡΠΈΠΈ', backgroundColor: '#ef9d4d', data: [1000, 400, 1500, 1500, 3000, 4000] }, { label: 'ΠΠΊΠΎΠ½ΠΎΠΌΠΈΡ Π½Π° ΡΠ΅Π½Π΅ Ρ ΡΡΠΎΠΉΠΊΠΈ', backgroundColor: '#476e8f', data: [1170, 460, 2000, 2500, 2700, 4000] }, ])
for (let el in item.data)? You donβt do anything with this loop, just insertitem.data6 times infirstArrandlastArr. - Dmitry