Question: How to merge duplicates in an array of objects and sum a specific property? [duplicate]. I am creating a JS chart, which I have done

How to merge duplicates in an array of objects and sum a specific property? [duplicate]. I am creating a JS chart, which I have done succesfully but I a lot having duplicates . Below is a sample JSON where I am retrieving data from to display on my Bar chart. I want to sum the duplcate values.

3123111310

3123111020

AHTSD111012

AHTSD111012

expected result below ==================================================================================== 3123111330

AHTSD111024

===================================================================================

$.ajax({ url: "http://localhost/api/Num", dataType: 'json', method: "GET", success: function (data) { parser = new DOMParser(); var xmlDoc = parser.parseFromString(data, "text/html"); data = xmlDoc.getElementsByTagName("JobCounts"); console.log(data); var serial = []; var prints = []; var scans = []; var copies = [];

for (i = 0; i < data.length; i++) {

serial.push("#" + data[i].getElementsByTagName("Serial")[0].textContent); prints.push(data[i].getElementsByTagName("Prints")[0].textContent); copies.push(data[i].getElementsByTagName("Copies")[0].textContent); scans.push(data[i].getElementsByTagName("Scans")[0].textContent); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!