Function: Convert an Array of Objects to an Array of Properties

by Simon Sparks · 1 November 2025

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

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

Filename: Utilities.ts

Relevant VMware KB Article Number: 445540

Relevant VMware KB Article URL: https://knowledge.broadcom.com/external/article/445540/custom-forms-fail-to-validate-with-error.html

Description: Orchestrator Function to Convert an Array of Objects to an Array of Properties

Function ConvertObjectArrayToArrayOfProperties ( for v9.1 and later )

  public static ConvertObjectArrayToArrayOfProperties<T>(arrUnknown: T[], strValuePropertyName: string = "id", strLabelPropertyName: string = "name"): { key: string, value: string, description: string }[] {

    let arrDropdown: { key: string, value: string, description: string }[] = arrUnknown.map((objUnknown: T): { key: string, value: string, description: string } => {

      let strKey: string = objUnknown[strValuePropertyName];
      let strValue: string = objUnknown[strLabelPropertyName];

      let objDropdown: { key: string, value: string, description: string } = {
        key: strKey,
        value: strValue,
        description: strKey
      };

      return objDropdown;
    });

    return arrDropdown;
  }
TypeScript

Function ConvertObjectArrayToArrayOfProperties ( for v8.x and v9.0 )

public static ConvertObjectArrayToArrayOfProperties<T>(arrUnknown: T[], strValuePropertyName: string = "id", strLabelPropertyName: string = "name"): Properties[] {

  let arrProperties: Properties[] = arrUnknown.map((objUnknown: T): Properties => {

    let strValue: string = objUnknown[strValuePropertyName];
    let strLabel: string = objUnknown[strLabelPropertyName];

    let objProperties: Properties = new Properties()
    objProperties.put("label", strLabel);
    objProperties.put("value", strValue);
    objProperties.put("description", strDescription);

    return objProperties;
  });

  return arrProperties;
}
TypeScript

Interface: DropdownBoxValue

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

Example of Usage:

let arrProperties: Properties[] = Utilities.ConvertObjectArrayToArrayOfProperties(arrVcVirtualMachine, "id", "name");
TypeScript

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like