I have this array structure in which at $arr[5]index I have a value that represents a number of occurrences for each object of my array $arr:
$arr=[
[
"some_value",
"some_value",
"cluster_0",
"area_2",
"some_value",
"1"
],
[
"some_value",
"some_value",
"cluster_0",
"area_2",
"some_value",
"2"
],
[
"some_value",
"some_value",
"cluster_0",
"area_3",
"some_value",
"1"
],
[
"some_value",
"some_value",
"cluster_1",
"area_3",
"some_value",
"3"
],
[
"some_value",
"some_value",
"cluster_1",
"area_4",
"some_value",
"2"
],
[
"some_value",
"some_value",
"cluster_1",
"area_4",
"some_value",
"2"
]
];
What I'm trying to obtain is to sum each of those$arr[5] values grouping by $arr[2](the cluster) and the $arr[3](the area).
Here's the expected output
$res=[
[
"cluster_0",
"area_2",
3
],
[
"cluster_0",
"area_3",
1
],
[
"cluster_1",
"area_3",
3
],
[
"cluster_1",
"area_4",
4
]
];
As you can see I have the sum of that specific value according to area and cluster matching. Is there any good approach in javascript for perform this kind of operation? I thought about a simple for loop and inside the loop an if condition for sum just the value that share the same $arr[2](the cluster) and the $arr[3](the area) values.