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)?

1

1 Answer 1

3

You can use Array.prototype.sort()

tasks.sort((currentValue: Task, nextValue: Task) => currentValue.priority - nextValue.priority);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.