Saturday 22 April 2017

Sorting objects based on a string value property in TypeScript

I have an array of objects and the definition for an object looks something like this:

export class AccountInfo {
  accountUid: string;
  userType: string;
  firstName: string;
  middleName: string;
  lastName: string;
}

NOTE: The reason I don't have userType as an enum is because the object is populated by a database call and I couldn't figure out a clean way to have the string returned from the db populate the enum.

I want to sort the array so that objects with a userType of 'STAFF' appear first, followed by 'TEACHER', then 'PARENT', then 'STUDENT'.



via TovrikTheThird

No comments:

Post a Comment