title: generic function for sorting array
body: <p>I wrote generic function for sorting array in typescript</p>
  <pre><code>export function sortArray(incomingArray: any[], sortField: string = '', sortOrder: string = 'asc'): any[] {
    if (!sortField) {
      return incomingArray;
    }
  
    let result: any[] = [];
    result = incomingArray.sort((a, b) =&gt; {
      let testData = a.ohlc['priceInUsd'];
  
      if (a[sortField] &lt; b[sortField]) {
        return sortOrder === 'asc' ? -1 : 1;
      }
  
      if (a[sortField] &gt; b[sortField]) {
        return sortOrder === 'asc' ? 1 : -1;
      }
  
      return 0;
    });
    return result;
  }
  </code></pre>
  <p>Wokring perfectly fine till structure is inside one array. Problem is if I have more complex data like in photo and then &quot;<code>a[sortField]</code>&quot; doesn't wok well any more</p>
  <p><a href="https://i.stack.imgur.com/W5tN8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W5tN8.png" alt="enter image description here" /></a></p>
  <p>How to chnage &quot;<code>a[sortField]</code>&quot; that will be more generic if I have more complex data and not need to write &quot;<code>a.x[sortField]</code>&quot;</p>