I was having some trouble when trying to sort and group the array items in JavaScript. Here is the sample inputs:
var arr = [
{merchantName: '', branchName: 'e', branchAddress: '', total: 10.5},
];
The output that I am trying to achieve:
var arr = [
{merchantName: '', branchName: '', branchAddress: '', total: 10.5},
];
I wanted to sort it in by branchName, for instance sum up the total for same branchName then at the same time bind all other attributes like merchantName and branchAddress together with it so that I can access them like:
for(var i = 0; i < arr.length; i++){
console.log(arr[i].merchantName + ' ' + arr[i].branchName + ' ' + arr[i].branchAddress + ' ' + arr[i].total);
}
I actually have no idea on how to even start it. Any ideas how to achieve it?