Forum Discussion

David91's avatar
David91
Frequent Contributor
3 years ago

Return [object Object]

Hi, i have a problem with this script. count return value [object Object]... why? Where i do mistake? This script should return ..

I need..

{ "a": 3, "b": 2, "c": 2, "d": 2, "e": 2, "f": 1, "g": 1, "h": 3 }

 

 

my Method

function getDuplicates() {
uniqueCount = ["a","b","c","d","d","e","a","b","c","f","g","h","h","h","e","a"];
var count = {};
uniqueCount.forEach(function(i) { count[i] = (count[i]||0) + 1;});
Log.Message(count)
}

 

Thank you

  • Hi David91.

     

    I believe the problem you are having is that testcomplete isn't converting the count object to a string to log as a message.  If you stopped testcomplete during debugging you would see counts' properties/fields and their associated values (first image).  If you want these to log as a string you will need to walk the object's fields (using aqObject.GetFields) and concatenate the field names and field values to a message string, like this...

     

     

    The logged messages

     

    I hope this helps.