2 Replies Latest reply on Apr 9, 2014 10:33 AM by Brian Knutsson

    HOW TO: Sort array of VC:HostSystems by Name

    Brian Knutsson Enthusiast



      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?




      var allHosts = VcPlugin.getAllHostSystems();

      HostNameToMatch = "ESXi";

      var hosts = new Array();



      for (var i in allHosts) {

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






      HostList = hosts;