1

I have an array with this mock:

export class Task {
  id: number;
  title: string;
  state: number;
  priority: number;
  describtion: string;
}

This array is filled with multiple entries and each has a priority from 1-5.

How can I sort this array by its priority (asc)?

Tom
  • 3,672
  • 6
  • 20
  • 52
  • Possible duplicate of [Sorting an array of JavaScript objects by property](https://stackoverflow.com/questions/979256/sorting-an-array-of-javascript-objects-by-property) – VLAZ Jul 10 '19 at 10:23

1 Answers1

3

You can use Array.prototype.sort()

tasks.sort((currentValue: Task, nextValue: Task) => currentValue.priority - nextValue.priority);
Thanh Le Hai Hoang
  • 1,313
  • 7
  • 14