dictionarycollectionsjscripttestcomplete

Iterate over a dictionary in TestComplete


I created a dictionary as follows and would like to loop over it and perform some actions.


dict.add("a",1);

dict.add("b",2);

dict.add("c",3);

for (var key in dict){

 Log.message("key is "+key+" and value is "+dict[key])

}

But the program does not enter the loop.

How can i iterate over the dictionary in Testcomplete?


Solution

  • After rounds of hit and trial, i think i have found the solution.

    var testData = [];
    testData["a"] = 1;
    testData["b"] = 2;
    testData["c"] = 3;
    
    for (var x in testData)
    {
        ...
    }