Most-succinct way to search an array of hash tables for a key

Question:

Assuming:

Using the Where-Object command to get COL_B‘s Measurements array:

Is there a more-succinct way of doing this? Would a nested set of PSCustomObjects be a better approach?

Answer:

If you are interested in looking element by key, than Hashtable will be better approach than array.

With Hashtable you can get Measurements array of COL_B by this command:

And If you want to enumerate all elements in Hashtable, then you can use following command:

In case if order of elements in hash table matters, you could use [ordered] operator before hash table literal to create OrderedDictionary instead of Hashtable.

Source:

Most-succinct way to search an array of hash tables for a key by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply