function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sumesh ChandranSumesh Chandran 

Sorting a trackable array in Lightning js

User-added imageThe data attached above is stored in a trackable array in lightning js. I am trying to sort the data by desc using the sumchans__Total_Buildings__c value.
 Here is the function that receives the trackable array and does the sorting, but it doesn't work.
The console log logs the right value, that works.
Please advise!
sortCityByNumberOfBldgs(province) {
console.log(JSON.stringify(this.ab[1].sumchans__City_Stats__r[0].sumchans__Total_Buildings__c));
    theData = JSON.stringify(province);
    theData.sort(function (a, b) {
      return ((a.sumchans__City_Stats__r[0].sumchans__Total_Buildings__c) - (b.sumchans__City_Stats__r[0].sumchans__Total_Buildings__c)) ? 1 : 0;
    })
    this.ab = theData;
  }