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.
expected result below ====================================================================================
===================================================================================
$.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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started