I Loop through a complex JSON object but I want to stop the loop after n iterations
n = 0;
maxIterations = 100;
ObjectValues = function(v, k){
if(n == maxIterations){
if (typeof v == "object") {
for (var kp in v) {
if (Object.hasOwnProperty.call(v, kp)) {
ObjectValues(v[kp], k != undefined ? k + "." + kp : kp);
}
}
} else {
console.log(k + ":" + v);
n++;
}
}else{
console.log('I should end the function');
return false;
}
};
But I can't exit the function with return false. The function gets called, even after I tried to exit it with return false.
if(n >= maxIterations)
and let us know. – Tolga Evcimen Jun 26 at 12:20n
on your if case? – Tolga Evcimen Jun 26 at 12:25return false;
then it means you are already in the function, it is already called. I couldn't understand the question. – Tolga Evcimen Jun 26 at 12:36