4 Replies Latest reply on Oct 4, 2010 10:02 PM by Fred Goldman

    [JS] Adding Methods to Associative Arrays

    Fred Goldman Level 3

      I have an associative array. I would like to add a method to it that will return an array of all the names of the associative array. The problem is it returns the name of the method, too. Is there any for it to only return the names of the properties and not the methods? In the code below I would like myEveryItem item to return an array of two items, not three.

       

      RangePresets = {};
      RangePresets.everyItem = getEveryItem;
      RangePresets["[Default]"] = new RangePreset(578,800);
      RangePresets["Daily Dose"] = new RangePreset(360, 600);
      myEveryItem = RangePresets.everyItem();
      
      // RangePreset Constructor
      function RangePreset(hr,vr){
           this.horizontalRange = hr;
           this.verticalRange = vr;
      }
      
      
      function getEveryItem(){
           var ei = [];
           for (x in this)
           ei.push(x);
           return ei;
      }