title: Dealing with null values position when sorting an array based on numeric values
body: <p><a href="https://stackblitz.com/edit/sorting-mfdvce?file=src/app/app.component.ts" rel="nofollow noreferrer">StackBlitz example</a></p>
  <p>Angular application. I am sorting an array into a <code>*ngFor</code> to loop through the results to display in sorted order.</p>
  <p>So the question isn't just a simple sort by numeric value. I have a list of users in an Array. Each user has a <code>sortId</code> of a number value, that's straightforward. e.g.</p>
  <pre><code>this.users.sort((a, b) =&gt; a.sortId - b.sortId);
  </code></pre>
  <p>this will give me a result like:</p>
  <pre><code>Row 1 - Sort ID: null - original array position: 7
  Row 2 - Sort ID: 1 - original array position: 4
  Row 3 - Sort ID: 2 - original array position: 1
  Row 4 - Sort ID: 3 - original array position: 3
  Row 5 - Sort ID: 4 - original array position: 6
  Row 6 - Sort ID: 5 - original array position: 8
  Row 7 - Sort ID: 6 - original array position: 5
  Row 8 - Sort ID: 7 - original array position: 2
  </code></pre>
  <p>However, I want to deal with <code>null</code> values by just skipping over them, maintain the their position of the original array - so the <code>null</code> above will be in the row 7(as its original array position was 7), regardless of whether there is a <code>sortId</code> of 7 already. <code>SortId: 7</code> will just go into row 8.</p>
  <p>Expected result:</p>
  <pre><code>Row 1 - Sort ID: 1 - original array position: 4
  Row 2 - Sort ID: 2 - original array position: 1
  Row 3 - Sort ID: 3 - original array position: 3
  Row 4 - Sort ID: 4 - original array position: 6
  Row 5 - Sort ID: 5 - original array position: 8
  Row 6 - Sort ID: 6 - original array position: 5
  Row 7 - Sort ID: null - original array position: 7
  Row 8 - Sort ID: 7 - original array position: 2
  </code></pre>
  <p>Field of users: (the arrayPosition property is just added for demo purposes, so can't be used.)</p>
  <pre><code>  users = [
      {
        user: 'fred',
        arrayPosition: 1,
        sortId: 2
      },
      {
        user: 'Gen',
        arrayPosition: 2,
        sortId: 7
      },
      {
        user: 'Billy',
        arrayPosition: 3,
        sortId: 3
      },
      {
        user: 'Sid',
        arrayPosition: 4,
        sortId: 1
      },
      {
        user: 'James',
        arrayPosition: 5,
        sortId: 6
      },
      {
        user: 'Tom',
        arrayPosition: 6,
        sortId: 4
      },
      {
        user: 'Jim',
        arrayPosition: 7,
        sortId: null
      },
      {
        user: 'Steve',
        arrayPosition: 8,
        sortId: 5
      }
    ];
  </code></pre>
  <p>I have got it working only when the <code>sortId</code> was lower than the original array position, otherwise it goes out of order:</p>
  <pre><code>  this.users.forEach(x =&gt; {
      this.fieldsList.splice(x['sortId'] - 1, 0, x);
    });
  </code></pre>
  <p>please help me and take a look at the <a href="https://stackblitz.com/edit/sorting-mfdvce?file=src%2Fapp%2Fapp.component.ts" rel="nofollow noreferrer">stackBlitz example</a>.</p>