I have a unique array structure that is as follows:
var array = [[
{ "location": {} },
{ "distance": 6.4 },
{ "zip1": "06120" },
{ "zip2": "06095" },
{ "group": 1 },
{ "weight": 1119 }
], [
{ "location": {} },
{ "distance": 6.41 },
{ "zip1": "06095" },
{ "zip2": "06120" },
{ "group": 2 },
{ "weight": 41976 }
], [
{ "location": {} },
{ "distance": 6.41 },
{ "zip1": "06095" },
{ "zip2": "06120" },
{ "group": 1 },
{ "weight": 41976 }
]];
My goal is to access the values in the array based on specific property values and display them in HTML format. The expected output should be segmented into separate arrays according to their "group" property. Below is an example of how I want the data to be presented:
group 1:
- list of all zip1's under group 1
group 2:
- list of all zip1's under group 2
I attempted to achieve this using a loop but unfortunately, I couldn't obtain the desired result:
for (var k = 0; k < array.length; k++) {
var currentArray = array[k];
if (flag[currentArray[2]["zip1"]]) continue;
flag[currentArray[2]["zip1"]] = true;
finalOutput.push(currentArray);
}
I need assistance in splitting the array and displaying it in an HTML format organized by groups.