15 ms·
This is so annoying. I’ve started using the preceding comma hack to force an array. $Ary = @(, "value") One cool feature for creating arrays (especially lar
by JoBrad 2y ago
This is so annoying. I’ve started using the preceding comma hack to force an array.
$Ary = @(, "value")
One cool feature for creating arrays (especially larger arrays, for performance improvements over using +=) is to assign your array to a for loop. It wasn’t an obvious method of populating an array to me, but is definitely handy.
$Ary = foreach ($Obj in $Objs) { @{ foo = $Obj.foo } }
- jmull 2y agoI think @("value") is enough. I use [array]$Ary = "value"
- Arnavion 2y agoI haven't used PS in many years, but I do remember `@("value")` would still end up unwrapping the single-element array back into its element in some situations, and the only sure-fire way to get an array was `, "value"` or `@(, "value")`