I have a powershell nested array with the below structure.
$jHosts = @(@("Host-1","Host-3"),@("Host-2","Host-4"),@("Host-5"))
As well as here is my powershell script to iterate the nested array.
for($i=0; $i -le $jHosts.Length; $i++){
Write-Host $jHosts[$i]
for($k=0;$k -le $jHosts.Length; $k++){
Write-Output $jHosts[$i][$k]
}
}
The Write-output
displays the output like below,
HOST-1
HOST-3
HOST-2
HOST-4
H
O
S
T
As my for loops reads all the values in first 2 nested arrays but it reads each character of a 3rd array's string when it is a single object. What am I doing wrong here?