Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

HOW TO: Sort array of VC:HostSystems by Name

$
0
0

Hi,

 

First off, I am new to Javascript.

I have the following javascript code, and I want to sort my HostList Array by Host name.

 

I tried the Array.sort(); function, but since it is objects, and not a list of hostnames. The result is done by Host name.

 

Does anyone know how to achieve the desired result?

 

/Brian

--------------------------------------

var allHosts = VcPlugin.getAllHostSystems();

HostNameToMatch = "ESXi";

var hosts = new Array();

 

 

for (var i in allHosts) {

  if (allHosts[i].name.match(new RegExp(HostNameToMatch, "i"))) {

  hosts.push(allHosts[i]);

  }

}

 

 

HostList = hosts;

HostList.sort();

--------------------------------------


Viewing all articles
Browse latest Browse all 6251

Trending Articles