looping through an object (tree)

Posted by Val on Stack Overflow See other posts from Stack Overflow or by Val
Published on 2010-03-30T23:06:45Z Indexed on 2010/03/30 23:13 UTC
Read the original article Hit count: 226

Filed under:
|
|

Is there a way (in jquery or javascript) to loop through each object and it's children and gandchildren and so on. if so... can i also read their name?

example

foo :{
  bar:'',
  child:{
    grand:{
      greatgrand: {
        //and so on
      }
    }
  }
}

so the loop should do something like this...

loop start
   if(nameof == 'child'){
     //do something
   }
   if(nameof == 'bar'){
     //do something
   }
   if(nameof =='grand'){
     //do something
   }
loop end

I know this is stupid code but i tried to make it understandable :)

btw this is for a jquery UI, as i am clueless how to go on about this.

thanks

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript