简体   繁体   中英

Cycling through jquery object to get its values

I have to loop through the object and get all its values. Here's an image of object 在此处输入图片说明
So, basically i have to get classificatorCodeId and loop through observationList to get its child classificatorCodeId's and observationLists, and so on.
If you guys have any ideas, what's the best way to loop through this object, id be happy to try your solutions.

Following code will print all values in that object as key --> value pairs

var traverse = function(mainObject)
{
  $.each(mainObject, function(index, subObject)
  {
    if(($.type(subObject) === "object" || $.type(subObject) === "array"))
    {
      traverse(subObject);
    }
    else
    {
      console.log(index+" --> "+subObject);
    }
  });
}

traverse(mainObject);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM