是否可以在VBScript中创建多维关联数组?
我正在尝试在VBScript中重新创建以下JScript代码:
names["teachers"] = ["Helen","Judy","Carol"];
names["students"] = ["George","John","Katie"];
For (var i=0; i<names["teachers"].length; i++) {
Response.Write(names["teachers"][i]);
}
我尝试的VBScript:
dim names
SET names = CreateObject("Scripting.Dictionary")
names.Add "teachers", Array("Helen","Judy","Carol")
names.Add "students", Array("George","John","Katie")
创建对象似乎没有错误,但我无法弄清楚如何在VBScript中循环遍历数组。
答案 0 :(得分:7)
迭代这个数据结构没有真正的技巧。你按照预期的方式去做。
For Each key In names
For i = 0 To UBound(names(key))
WScript.Echo "names(" & key & ")(" & i & ") = " & names(key)(i)
Next
Next