javascript - Loop over child objects -


i'm trying loop on child objects within object using $(parent).each() return parent. in below code, console.log() both print same thing. want iterate on children "rectangle", "pointend" , "pointstart" objects , children.

moveitemsobjarray = []; moveitemsobj = {}; mobeitemsobj.pointer = guidvarible; moveitemsobj.nodes =  {"rectangle":{                           "rect_x": linerect_x,                           "rect_y": linerect_y,                           "rect_w": linerect_w,                           "rect_h": linerect_h                         },                         "pointstart":{                           "point_x": newpointstart_x,                           "point_y": newpointstart_y                         },                         "pointend": {                           "point_x": newpointend_x,                           "point_y": newpointend_y                         }                       };                       moveitemsobjarray.push(moveitemsobj); });   $(moveitemsobjarray).each(function(){   var nodes = this.nodes;     console.log(nodes);   $(nodes).each(function(){     console.log(this);   }); }); 

and this?

$.each(nodes, function(i, node) {     $.each(node, function(i, child) {         console.log(child); // normal value         console.log($(child)); // make jquery object     }); }); 

in vanilla js can use for(var node in nodeobjects) return index. jquery have both i, value in .each function.

both examples here.


Comments

Popular posts from this blog

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -