the point is, sometimes i receive a json object like

      var json = {
          element: ['1','2','3']
      }

      and sometimes element has just one element so it is presented as
a String not an Array:
      var json = {
          element: '1'
      }

      And i want to iterate over json.element independently of its
type, i normally do something like:

      objectToArray(json.element).each(function(ele){ ... }.bind
(this));

      where objectToArray is something like this:

      function objectToArray(obj) {
            if (!Object.isArray(obj) && !Object.isHash(obj)) {
                   var objArray = [obj];
                   return objArray;
            }
            return obj;
       }
       So my question is, it is possible doing that by adding the each
() method to the Object class,
       and making it do something like objectToArray(this) before
iterating over the this object?

       Sorry if i havenĀ“t explained well.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to