|
Re: Array Indexes On Aug 13, 1:13 pm, Shay Levi <n...@addre.ss> wrote:
> The following returns all array items that equels to 3
>
> PS C:\Scripts> @(1,2,3,5,3,2) -eq 3
> 3
> 3
>
> How can I get the index numbers instead of the item content (i.e., 2,4)?
>
> Shayhttp://scriptolog.blogspot.com
Someone will probably be along with a better answer in a bit, but from
what I can see there is no native member of the array class that will
return a collection of indicies rather than types.
Ofcourse you could always just loop through the array and return each
index - or build up your own collection if you need them alltogether
for($i=0; $i -lt $a.length; $i++) {if($a[$i] -eq 3) {$a[$i]}}
There is another option of using the [array]::IndexOf() method, this
only returns the first match, but there's an overloaded signature that
constricts the start and end indicies that govern the search, so you
could call it iteratively. I figure by the time you've done this
you've created more work than the above simple loop though.
Regards,
Duncan |