jQuery nested each continue
by amindunited
JavaScript
//Much like using continue to go to the next parent loop, but using jQuery.each, and wrapping the loops in funtions
var target_object = {
a : {1:"a_1", 2:"a_2", 3:"a_3", 4:"a_4"},
b : {1:"b_1", 2:"b_2", 3:"b_3", 4:"b_4"},
c : {1:"c_1", 2:"c_2", 3:"c_3", 4:"c_4"},
d : {1:"d_1", 2:"d_2", 3:"d_3", 4:"d_4"}
}
//Loops through each alphabetical index, and skips "b"
function each_alph(){
$.each(target_object, function(i, obj){
if (i==="b") {
return true;
} else {
each_num(obj);
}
})
}
//Loops through each numeric index, and skips "3"
function each_num(pointer){
$.each(pointer, function(i, obj){
if (i==="3") {
return true;
}
else {
console.log("reading ", i, obj)
}
})
}
$(function(){
each_alph();
})