PowerShell: Join Array, Append

By Xah Lee. Date: . Last updated: .

🛑 WARNING: Array type is fixed size data structure. when you add item, PowerShell creates a new array. The more items in a array, the slower it is to create a new array.

Append an Item

Use operator += to add a item to end of array.

$x = @(1, 2, 3)

# add a item "b" to the end
$x += "b"
Write-Host $x
# 1 2 3 b

Join Arrays

use + operator.

$a = @(1,2)
$b = @(3,4,5)
$c = $a+$b
Write-Host $c
# 1 2 3 4 5

PowerShell. Array