continue works only in loops with an array (for (...)), how to make continue in a loop with an object? return exits the function, break completes the loop, but do I need to go to the next iteration in the loop on the object?

for (key in obj) { if (typeof obj[key] == 'function') { continue; } path += '.' + key; if (typeof obj[key] == 'string' && obj[key] == this.hash) { this.linkToHash.push(path); continue; } if (typeof obj[key] == 'object') { this.findHash(obj[key], path); path = objPath; } } 

Closed due to the fact that off-topic participants Grundy , user207618, user194374, Denis , pavel 13 Aug '16 at 6:16 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Grundy, Community Spirit, Community Spirit, Denis
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Are you really sure that you need to write this way? - Mihanik71
  • No, offer your own implementation, a simple example - Khotey Vitaliy
  • one
    I do not see problems with continue and object. Give an example that can reproduce the problem - Grundy
  • the point is that continue does not work on iterations on the object, the cycle simply does not see it and goes further - Khotey Vitaliy
  • @KhoteyVitaliy, I'm just talking about the fact that continue works exactly as expected. And without a minimal reproducible example you cannot say why it doesn’t work for you - Grundy

1 answer 1

 for (key in obj) { if (typeof obj[key] != 'function'){ path += '.' + key; if (typeof obj[key] == 'string' && obj[key] == this.hash) { this.linkToHash.push(path); }else if (typeof obj[key] == 'object') { this.findHash(obj[key], path); path = objPath; } } } 

Version 2:

 for (key in obj) { switch(typeof obj[key]) { case 'function': break; case 'string': if(obj[key] == this.hash) this.linkToHash.push(path); break; case 'object': this.findHash(obj[key], path); path = objPath; break; } } 
  • it is so, but such a code is hard to test) can you somehow do without embedding? - Khotey Vitaliy
  • Is the continue code easy to test? - Mihanik71
  • yes, one if one test - Khotey Vitaliy
  • Added another option - Mihanik71