Forum Discussion

SuperTester's avatar
SuperTester
Contributor
4 years ago

Sorting an Array Object from FindAll

Hey guys!   I'm trying to figure out how to sort an array of objects by a certain property. However, I'm encountering an error where TC is saying "tableArray.sort is not a function". Code: const ...
  • SuperTester's avatar
    SuperTester
    4 years ago

    Hey Marsha_R

    I think I just figured it out.

     

    By adding the .toArray command, the comSafeArray was converted to an array object and I can use the sort method.

     

    var tableArray = window.FindAllChildren("JavaClassName","UITablePeer$23",2000,true).toArray()

    var sortedTableArray = tableArray.sort(function(a,b){return a.Left - b.Left})

     

    Now, the documentation for the FindAll and FindAll children does warn that  JScript, C#Script and C++Script users need to convert using toArray(), but I did not think this applied to me since I'm coding in Javascript.