0

Is there a way of finding out if a given value is in an array without iterating through it? Something like the in_array function in PHP...

closed as off-topic by Christoffer, Waqas Sarwar MVP, wjervis, Robert Lindgren Dec 4 '15 at 6:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Christoffer, Waqas Sarwar MVP, wjervis, Robert Lindgren
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Yes, there is. Example:

$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors -contains "black"
#$arrColors -notcontains "black" #obvious
#$color = $arrColors -like "bl*" #return all values that begin with "bl"

or

$array = 1,2,5,8,3,4,5
$array.Contains(2)

Both examples return a boolean.

Not the answer you're looking for? Browse other questions tagged or ask your own question.