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

      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: Core" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to