JSFiddle - React, Tailwind, and code Playground

by arcm111

JavaScript

var Result = [
    {"id": 1, "name": "Mark", "joinDate": "2014-05-03T22:12:05.000Z", "balance": 2000},
    {"id": 2, "name": "Jack", "joinDate": "2014-05-05T22:12:05.000Z", "balance": 3000},
    {"id": 3, "name": "John", "joinDate": "2014-05-01T22:12:05.000Z", "balance": 1500},
    {"id": 4, "name": "Jane", "joinDate": "2014-05-01T22:12:05.000Z", "balance": 3500},
    {"id": 5, "name": "Sarah", "joinDate": "2014-05-05T22:12:05.000Z", "balance": 1000},
    ];

    var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    
    var groupedResult = [];
    for (var i = 0; i < Result.length; i++)
    {
        var date = new Date(Result[i].joinDate), day = date.getDate(), month = months[date.getMonth()], year = date.getFullYear(), d = "day " + day;
    
        if (!groupedResult.hasOwnProperty(year)) groupedResult[year] = {};
        if (!groupedResult[year].hasOwnProperty(month)) groupedResult[year][month] = {};
        if (groupedResult[year][month].hasOwnProperty(d))
        {
            groupedResult[year][month][d].no_of_clients += 1;
            groupedResult[year][month][d].balance += Result[i].balance;
        }
        else groupedResult[year][month][d] = {"id": day, "no_of_clients": 1, "balance": Result[i].balance};
    }

console.log(groupedResult);