I knew that combining to similar data structures wouldn't be logical but curious to know if we can have a array element inside Dictionary object. some thing like:
Set d = CreateObject("Scripting.Dictionary")
d.Add "Name", "John"
d.Add "Age", 31
d.Add "Company", Array("microsoft", "apple")
You are one WScript.Echo
away from solving the question for yourself:
>> Set d = CreateObject("Scripting.Dictionary")
>> d.Add "Company", Array("microsoft", "apple")
>> WScript.Echo Join(d("Company"))
>>
microsoft apple
cf this question
Update (thanks to @Ansgar):
The elements delivered by .Item()
(and For Each
) are copies; and Array assignment copies too (does not take a reference as in other languages). So changing an array element stored in a dictionary means assigning a new array:
>> Set d = CreateObject("Scripting.Dictionary")
>> d.Add "Company", Array("microsoft", "apple")
>> WScript.Echo Join(d("Company"))
>> d("Company") = Array(d("Company")(1), "samsung")
>> WScript.Echo Join(d("Company"))
>>
microsoft apple
apple samsung
Sometimes it's more convenient to use a(nother) dictionary, a System.Collections.Arraylist, or a custom object (all objects are references, so an assignment gives access to the original element).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With