How can I use the Array.Find method in powershell?
For example:
$a = 1,2,3,4,5
[Array]::Find($a, { args[0] -eq 3 })
gives
There is no need to use Array.Find, a regular where
clause would work fine:
$a = @(1,2,3,4,5)
$a | where { $_ -eq 3 }
Or this (as suggested by @mjolinor):
$a -eq 3
Or this (returns $true
or $false
):
$a -contains 3
Where
clause supports any type of objects, not just basic types, like this:
$a | where { $_.SomeProperty -eq 3 }