I have an array where each element is a hashtable. Each hashtable has the same keys. Here it is:
@(
@{"MarketShortCode"="abc";"MarketName"="Market1" },
@{"MarketShortCode"="def";"MarketName"="Market2" },
@{"MarketShortCode"="ghi";"MarketName"="Market3" },
@{"MarketShortCode"="jkl";"MarketName"="Market4" }
)
I want a nice elegant way to extract an array containing just the value of the MarketShortCode key. So I want this:
@("abc","def","ghi","jkl")
This is the best I've come up with:
$arr = @()
$hash | %{$arr += $_.MarketShortCode}
$arr
But I don't like that cos its three lines of code. Feels like something I should be able to do in one line of code. Is there a way?