Let's say I have a list of associative arrays.
I want to iterate over this list by groups. First by category, then, in a nested loop, by subcategory.
aalist = {
[
"Category" => "A",
"Subcategory" => "aa",
"Value" => "123"
]
,
[
"Category" => "A",
"Subcategory" => "aa",
"Value" => "124"
]
,
[
"Category" => "A",
"Subcategory" => "bb",
"Value" => "125"
]
,
[
"Category" => "A",
"Subcategory" => "bb",
"Value" => "124"
]
,
[
"Category" => "A",
"Subcategory" => "cc",
"Value" => "125"
]
,
[
"Category" => "B",
"Subcategory" => "aa",
"Value" => "126"
]
,
[
"Category" => "B",
"Subcategory" => "aa",
"Value" => "127"
]
,
[
"Category" => "B",
"Subcategory" => "bb",
"Value" => "127"
]
,
[
"Category" => "B",
"Subcategory" => "bb",
"Value" => "126"
]
,
[
"Category" => "B",
"Subcategory" => "cc",
"Value" => "127"
]
,
[
"Category" => "B",
"Subcategory" => "cc",
"Value" => "127"
]
,
[
"Category" => "B",
"Subcategory" => "cc",
"Value" => "126"
]
};Meaning that in my first loop on the first iteration I get a list of associative arrays where Category is "A". In the nested loop I iterate through subcategories, where on first iteration I get a list of all associative arrays with Subcategory "aa", and so on.
A good example of what I need to accomplish can be shown in PowerShell as follows:
# Sample data
$data = @(
[PSCustomObject]@{ Name = "Alice"; Group = "A" }
[PSCustomObject]@{ Name = "Bob"; Group = "B" }
[PSCustomObject]@{ Name = "Charlie"; Group = "A" }
[PSCustomObject]@{ Name = "David"; Group = "B" }
)
# Group the data by the 'Group' property
$groupedData = $data | Group-Object -Property Group
# Iterate over each group
foreach ($group in $groupedData) {
Write-Host "Group: $($group.Name)"
# Iterate over each item within the group
foreach ($item in $group.Group) {
Write-Host " Name: $($item.Name)"
}
}How do I do something like that in JSL?