PowerShell: Array, Set Item

By Xah Lee. Date: . Last updated: .

Set Array Element (syntax)

$x = 1, 2, 3
$x[0] = "b"
Write-Host $x
# b 2 3

SetValue (method)

SetValue(val, index)

$x = 1, 2, 3
$x.SetValue("b",0)
Write-Host $x
# b 2 3

Delete Item

It's not easy to delete array item in PowerShell. Array data structure is not designed to change size. Instead of delete, just replace the item by $null

PowerShell. Array