public addition :any = [];
public display : any = [];
public object1 =['3','2','1'];
public value2 =['5','7','9','8'];
constructor(){}
ngOnInit(){
this.addition=this.object1.concat(this.value2);
this.display=this.addition.sort();
}
如何使用angular 2或更高版本的typescript以降序对数组进行排序 Complete code Here
答案 0 :(得分:4)
答案 1 :(得分:2)
您的代码
this.display=this.addition.sort();
将按升序对数组进行排序,以降序排序,您需要传递比较器函数。
this.display=this.addition.sort((a,b) => b - a);