Ionic 3 how to seperate sort array


I need separate descending results for points and rebounds in one API call.

please see below my codes.

    .map(res => res.json())
    .subscribe(data => {
      this.dataLeaders =;  

      //sort api to points
      let pointsL =  this.dataLeaders.sort(function(a, b) {
          return parseInt(b.sPoints) - parseInt(a.sPoints);

      //sort api to rebounds
      let reboundL =  this.dataLeaders.sort(function(c, d) {
        return parseInt(d.sReboundsTotal) - parseInt(c.sReboundsTotal);

    }, err => {

my problem is it’s both sorting with rebounds instead of sort for points and sort for rebounds

Try the following:

 //sort api to points
this.points = JSON.parse(JSON.stringify(this.dataLeaders));
let pointsL =  this.points.sort(function(a, b) {
          return parseInt(b.sPoints) - parseInt(a.sPoints);
1 Like

@JAR19 Thanks, it works

Glad to help - but be careful - I use the Json.parse/stringify in my code but some times it keeps a reference to the base data - A better solution might be to use angular.copy() which does a deep copy or easier still have two separate http calls and therefore the data is totally separated.