Contributor
Contributor

Declare Variable

Hi,

How do we declare/create Array of Virtual machines parameter in javascript code (instead of creating it as input or output paramater in VRO).

Please help.

0 Kudos
1 Reply
VMware Employee
VMware Employee

Hi,

Javascript is kind of dynamic/typeless language, so you just declare a plain array. Something like:

// declare the array

var vms = []; // or alternatively -> var vms = new Array()

// add element(s) to it

var vm1 = Server.findForType("VC:VirtualMachine", "<some-vm-id>");

vms.push(vm1);

// access the array or individual elements

System.log("First element: " + vms[0]);

System.log("Array of VMs: " + vms);

0 Kudos