Forum Discussion
read elements of an array simultaneously
Not sure exactly what you mean, you can get all the elements by simply referencing the array variable? Or use something like $testarray.GetEnumerator() or $testarray.Split().
Thanks for your reply Vasil, here is what I have (sample code)
$testarray = ("a", "b", "c", "d")
foreach ($x in $testarray) {
print $x
}
This loop actually iterates this array and prints
a
b
c
d
Now I wanted to perform it in a way that this print statement is executed on all elements at once and so that result is like
a b c d
- Kevin_MorganFeb 20, 2019Iron Contributor
Hi,
You can achieve this by "join" method.
$testarray = ("a", "b", "c", "d")
$testarray -join " "
#For comma separated values
$testarray -join ","
- rahulrunsFeb 20, 2019Copper Contributor
Thank you for your reply, I will try to be clearer on what I intent to do. $testarray (with join it will have field separators) will print array but will not help me do a simultaneous operation on all elements of an array. What I wrote is just sample where if I replace print statement with anything else it should work on all elements simultaneously
- VasilMichevFeb 20, 2019MVP
What exactly are you trying to do?