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

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

Function ConvertObjectArrayToArrayOfProperties

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("value", strValue);
    objProperties.put("label", strLabel);

    return objProperties;
  });

  return arrProperties;
}

Example of Usage:

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

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like