如何在 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);
谢谢!
原文由 Maurizio Rizzo 发布,翻译遵循 CC BY-SA 4.0 许可协议
升序排序
降序排序