返回一個(gè)數(shù)組,其中包含了一個(gè) Dictionary 對(duì)象中的全部現(xiàn)有的關(guān)鍵字。
object.Keys( )
其中 object 總是一個(gè) Dictionary 對(duì)象的名稱(chēng)。
下面這段代碼說(shuō)明了 Keys 方法的用法:
[JScript] function KeysDemo() { var a, d, i, s; // 創(chuàng)建一些變量。 d = new ActiveXObject("Scripting.Dictionary"); d.Add ("a", "Athens"); // 添加一些關(guān)鍵字和項(xiàng)目。 d.Add ("b", "Belgrade"); d.Add ("c", "Cairo"); a = (new VBArray(d.Keys()
)).toArray(); // 獲取關(guān)鍵字。 s = ""; for (i in a) // 遍歷 dictionary。 { s += a[i] + " - " + d(a[i]) + "<br>"; } return(s); // 返回結(jié)果。 } [VBScript] Function DicDemo Dim a, d, i ' 創(chuàng)建一些變量。 Set d = CreateObject("Scripting.Dictionary") d.Add "a", "Athens" ' 添加一些關(guān)鍵字和項(xiàng)目。 d.Add "b", "Belgrade" d.Add "c", "Cairo" a = d.Keys
' 獲取關(guān)鍵字。 For i = 0 To d.Count -1 ' 迭代數(shù)組。 s = s & a(i) & "<BR>" ' 返回結(jié)果 Next DicDemo = s End Function
Add 方法 (Dictionary) | Exists 方法 | Items 方法 | Remove 方法 | RemoveAll 方法
應(yīng)用于:Dictionary 對(duì)象