Where is PowerShell’s special array head/tail assignment documented?


I only just noticed that this is valid PowerShell code:

This statement puts the first item in the array in $first and the remaining items in $rest.

It even works for an arbitrary number of variables, pushing the current head into the next variable and the tail into the last one. You can try that for yourself.

It seems to assign a $null value if there aren’t enough heads or tails to put into one of the variables. Even in the case of the $rest (I’d rather have seen an empty array, but whatever).

The problem, and my question, is that I don’t see this documented anywhere! I’m trying to find out when this was supported. Exactly how it’s implemented. If it works for any other types.

I checked about_Assignment, about_Arrays, and about_Splatting, without any luck.


See the following section near the bottom of about_Assignment_Operators

Assigning multiple variables

In PowerShell, you can assign values to multiple variables by using a single command. The first element of the assignment value is assigned to the first variable, the second element is assigned to the second variable, the third element to the third variable, and so on. This is known as multiple assignment.


Where is PowerShell’s special array head/tail assignment documented? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply