If I have one array of objects with inner properties like so:
var array = [
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.004.002",
},
{
"Structure_SortID": "001.004.002",
}
];
How can I reduce this one array into a single 2D array that contains 2 arrays of matching "Structure_SortID" properties? Output should be:
var array = [
// Filtered so only 001.004.002
[
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
},
{
"Structure_SortID": "001.001.003",
}
],
// Filtered so only 001.004.002
[
{
"Structure_SortID": "001.004.002",
},
{
"Structure_SortID": "001.004.002",
}
]
];
The solution needs to allow for an infinite number of lists with matching "Structre_SortID" properties. And needs to support situations where there is only 1 array of matching ID's inside the 2D array. And needs to support empty arrays or single item arrays alongside matching lists inside the 2D array.
var array = [ '001.004.003': { { "Structure_SortID": "001.001.003", }, .... { "Structure_SortID": "001.001.003", } }, '001.004.002': { { "Structure_SortID": "001.004.002", }, { "Structure_SortID": "001.004.002", } } ];and then do another for loop and make the object an array as your example