Given this input:
$values = @(1, @(2, 3), $null, @(@(4), 5), 6)
What is necessary to create a clean iteration/pipeline over
1,2,3,4,5,6
?
Conditions:
$null
in the output.Bonus:
[1,2,3,4,5,6]
as the result of ConvertTo-Json -Compress
I've seen Flatten array in PowerShell, the solutions there do not seem to fulfill the conditions.
@(1, @(2, 3), $null, @(@(4), 5), 6) | %{$_} | ?{$_ -ne $null}
The output:
1
2
3
4
5
6
The ForEach-Object
cmdlet (%
) flattens arrays by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With