How to check if associative array is free in powershell

$a = @() 

How to check if $a above empty (what it is). I would like to get $true as an answer.

+5
source share
2 answers

This is not an associative array, this is a regular array, but the answer is the same. Use .Count and compare with 0.

An associative array is called [hashtable] in PowerShell, and its literal form uses @{} (curly braces).

 @{}.Count -eq 0 # hashtable (associative array) @().Count -eq 0 # array 
+11
source

Arrays have the Count property, and you can check if this value is 0. So the condition you should check is

 $a.Count -eq 0 
+2
source

All Articles