I'm looping trough 2-dimensional objects inside an array. I currently do this the following way:
My array looks like this
var myarray = [
0: {
child_obj: {}
}
1: {//etc}
];
And I loop through the second-level objects like this
jQuery.each(myarray, function(i, first) {
jQuery.each(first.child_obj, function(j, second) {
//do stuff
}
});
});
So that's a loop inside a loop. It works fine, but it doesn't look very neat and I feel there might be a better (and shorter) way to do this.
The reason I'm doing this is because I need to do stuff with all child_objs.
Worth mentioning:
- I use
jQuery.each()because this allows looping through objects, whilefor(),.map()etc. can't handle that properly. - I can't change the structure of the array or its contents
- I don't need to use the indexes (args
iandj).
Is there a better way?
var myarray = [].. I edited the question :)