title: Sorting Array in TypeScript (Ionic)
body: <p>I'm trying to sort my array by id. However, when I use the sort() method nothing happens. </p>
  
  <pre><code>products.sort(function (a, b) {
    return a.id - b.id;
  });
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>My attempt:</p>
  
  <pre><code>constructor(private pokemonService: PokemonService, private typeColorFactory: TypeColorFactoryService, private screenOrientation: ScreenOrientation) {
      this.pokemonService.getPokemons(1).subscribe(
        res =&gt; {
          console.log(res);
  
          this.pokemons = res;
          this.pokemons.sort((a, b): Pokemon =&gt; {
            if (a.id &lt; b.id) return -1;
            if (a.id &gt; b.id) return 1;
            return 0;
          });
          console.log(this.pokemons);
        },
        err =&gt; {
          console.log('HTTP Error', err);
        }
      );
    }
  </code></pre>
  
  <p>The array always stays the same! I don't know if it matters, but when I <code>console.log()</code> within the sort, it doesn't log anything (don't know if that is possible though).</p>
  
  <p>Model: </p>
  
  <blockquote>
    <p>pastebin.com/FLTiZPSA</p>
  </blockquote>
  
  <p>Data:</p>
  
  <blockquote>
    <p><a href="https://i.stack.imgur.com/S8GVl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S8GVl.png" alt="data"></a></p>
  </blockquote>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>const products=[
    {'id':'1','name':'A'},
    {'id':'3','name':'C'},
    {'id':'4','name':'D'},
    {'id':'2','name':'B'},
  ];
  products.sort((a,b)=&gt; {
    console.log("test");
    return a.id-b.id;
  });
  this.pokemons.sort((a,b) =&gt; {
    console.log("test");
    return a.id-b.id;
  });
  </code></pre>
  
  <p>products.sort() DOES log "test".</p>
  
  <p>this.pokemons.sort() DOES NOT log "test".</p>
  
  <p>Link to this.pokemonService: <a href="https://pastebin.com/raWJ9isP" rel="nofollow noreferrer">https://pastebin.com/raWJ9isP</a></p>