Function: Sort an Array of Properties

by Simon Sparks · 29 January 2026

To use this function add it to the class library file named Utilities.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: Utilities.ts

Function sortArrayOfProperties

Description: Orchestrator Function to Sort an Array of Properties ( for v9.1 and later )

public static sortArrayOfProperties(arrDropdownBoxValue: DropdownBoxValue[], enumSortOrder: SortOrder = SortOrder.Forward): DropdownBoxValue[] {

  arrDropdownBoxValue = arrDropdownBoxValue.sort((objDropdownBoxValueA: DropdownBoxValue, objDropdownBoxValueB: DropdownBoxValue): number => {

    let strKeyA: string = objDropdownBoxValueA["key"];
    let strKeyB: string = objDropdownBoxValueB["key"];

    return this.compareTwoString(strKeyA, strKeyB, enumSortOrder);
  });

  return arrDropdownBoxValue;
}

Description: Orchestrator Function to Sort an Array of Properties ( for v8.x and v9.0 )

public static sortArrayOfProperties(arrProperties: Properties[], enumSortOrder: SortOrder = SortOrder.Forward): Properties[] {

  arrProperties = arrProperties.sort((objPropertiesA: Properties, objPropertiesB: Properties): number => {

    let strA: string = objPropertiesA.get<string>("label");
    let strB: string = objPropertiesB.get<string>("label");

    return this.compareTwoString(strA, strB, enumSortOrder);
  });

  return arrProperties;
}

Enumeration: SortOrder

export enum SortOrder {
  Forward = "Forward",
  Reverse = "Reverse"
}

Interface: DropdownBoxValue

export interface DropdownBoxValue {
    key: string;
    value: string;
    description: string;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like