如何在TypeScript中对对象数组进行排序?
具体来说,在一个特定属性上对数组对象进行排序,在本例中为nome(“name”)或cognome(“surname”)?
/* Object Class*/ export class Test{ nome:String; cognome:String; } /* Generic Component.ts*/ tests:Test[]; test1:Test; test2:Test; this.test1.nome='Andrea'; this.test2.nome='Marizo'; this.test1.cognome='Rossi'; this.test2.cognome='Verdi'; this.tests.push(this.test2); this.tests.push(this.test1);
谢谢!