4 Replies Latest reply on Mar 25, 2013 5:45 PM by CarlosCanto

    Listing Font Families in an Array (or not), 3 questions

    aklyman Level 1

      I'm building a script that will open a dialog box allowing the user to select a font family from a drop down list (not a list of all of the fonts), and then compare that value against the fonts that are in use, highlighting everything that doesn't match. I have not yet built the dialog, but I've got  everything else working as I want except the list of font families.


      The following code loops through the list of fonts (only 20 for testing purposes), compares the family name to the previous on the list (error trapped for the first loop), and pushes the family name (if it doesn't match the previous) into an array which will be used in the dialog box. With the two alerts at the bottom (for troubleshooting), I expect the alerts to show the same family name. For the first three fonts they do, but after that the array value is "undefined." 


      var iCount = 20;

      //var iCount = textFonts.length;

      var nameHolder = "";

      var nameArray = new Array();


      for(var i=0; i<iCount; i++) {

         var familyName = textFonts[i].family;

          try{nameHolder = textFonts[i-1].family;;}

          catch (err){nameHolder = "";}

          if (familyName != nameHolder ){


              alert ("Family Name: " + familyName);

              alert ("Name Array: " + nameArray[i]);






      1) Any speculation on why this behavior is happening (it isn't truetype versus opentype)?

      2) Is there a better way to get the list of font families without duplicates??

      2) Is an array the best way to populate a dropdown list in a JS dialog box??? [this will be my first dialog with a dropdown, the others have user-typed values]





      EDIT: Additional Info

      When it reaches the ninth font in the list, the above script starts writing undefined, but when tested manually, as below, it works fine. Hmmm.


      alert (textFonts[9].family);

      var nameArray = new Array();


      alert (nameArray[0]);


      EDIT: More info

      tried replacing nameArray.push(familyName); with nameArray.splice(i,0,familyName); bad behavior remains