[ {"ip":"123","data":"2019-02-27 21:05:11","type":"1","source_id":123}, {"ip":"123","data":"2019-02-27 21:07:37","type":"1","source_id":135}, {"ip":"123","data":"2019-02-27 22:03:33","type":"1","source_id":123}, {"ip":"123","data":"2019-02-28 22:06:00","type":"1","source_id":123} ] 

there is json how to calculate the same fields to remove them and send 5 parameters the number of identical parameters For any idea I will be grateful json is needed to build a chart for amcharts 4

Example

  [ {"ip":"123","data":"2019-02-27 21:05:11","type":"1","source_id":125,"total":1}, {"ip":"123","data":"2019-02-27,"type":"1","source_id":125,"total":4} ] 

Closed due to the fact that the essence of the question is incomprehensible to the participants by Igor , 0xdb , freim , aleksandr barakin , LFC on 3 Mar at 8:37 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Add the desired result to the question. - Igor
  • Create a class and serialize it. Or add a function for data processing - Vitaly Shebanits pm
  • Which field do you want to group? - Vitaliy Shebanits
  • by source id so that it has a uniqueness - Alexander Shvedov

1 answer 1

 let mass = [ {"ip":"123","data":"2019-02-27 21:05:11","type":"1","source_id":123}, {"ip":"123","data":"2019-02-27 21:07:37","type":"1","source_id":135}, {"ip":"123","data":"2019-02-27 22:03:33","type":"1","source_id":123}, {"ip":"123","data":"2019-02-28 22:06:00","type":"1","source_id":123} ] console.log(group(mass)); function group(arr) { let res = []; arr.forEach(el => { if (res.length === 0) { el.total = 1; res.push(el); } else { res.every(elem => { if (el.source_id === elem.source_id) { elem.total++; return; } else { el.total = 1; res.push(el); } }); } }); return res; } //console.log(res);