Answer the question
In order to leave comments, you need to log in
Why doesn't .indexOf() work?
Hi all!
Faced the following problem.
I have an array of strings and perform the following operations with them, for example:
$arr = @("sometext", "value1","somethingelse")
$temp = $arr -imatch "val"
$arr.indexOf($temp)
[array]::IndexOf($arr, $temp)
Answer the question
In order to leave comments, you need to log in
Comments
This method searches all elements of a one-dimensional arrayfor value. To determine whether value exists in array, the method performs equality comparisons by calling each element's Equals method until it finds a match. This means that if an element overrides Object.Equals(Object) that override's method is called.
PS > $arr[1].Equals($temp)
False
PS > $arr[1].Equals("$temp")
True
Therefore:
PS > $arr.indexOf("$temp")
1
PS > [array] ::IndexOf($arr, "$temp")
1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question