typeScript how to sort an array into an array
<p>I Have a class</p>

<pre><code>export class TestClass {
    id: number;
    text1: string;
    test2: string;
    text3: string;
</code></pre>

<p>and another </p>

<pre><code>export class testClassRow {
    editable: boolean;
    testClass : TestClass ;
}
</code></pre>

<p>In my code , i have an array wich is filled with some data  , thus</p>

<pre><code>x:testClassRow[]; 
</code></pre>

<p>I want to sort my x  and the sort key is text1.</p>

<p>I wrote a method that does the sort but it does not work
this is my method :</p>

<pre><code>    sort(key, data) {

    if (this.key === key) {
        this.direction = this.direction * -1;
    } else {
        this.direction = 1;
    }

    this.key = key;
    data.applicationLink.sort((a, b) =&gt; {
        console.log('avlu' + a[key]);
        if (a[key] === b[key]) {
            return 0;
        }
        else if (a[key] &gt; b[key]) {
            return 1 * this.direction;
        } else {
            return -1 * this.direction;
        }
    });
</code></pre>

<p>key has the value text1 for exemple </p>