Need to return an array element from a hashtable based upon if the key's array contains a certain value
Solution 1:
I'm not quite sure if this is what you're looking for:
$ht = @{
"Name" = @("Release", "Build", "Test", "CI/CD")
"Type" = @(
"Release Workflow", "Build Workflow"
"Testing Workflow", "CI/CD Workflow"
)
}
$key = "Release"
# Might want to use `-contains $key` or `$key -in` here
if($ht.Name.Contains($key)){
$ht['Type'][$ht['Name'].IndexOf($key)]
}
Note that, the .Contains(..)
array method is case-sensitive, you might want to use -contains
or -in
operators for a case-insensitive lookup.