Last active
December 22, 2015 04:58
-
-
Save ondrek/6420665 to your computer and use it in GitHub Desktop.
How to iterate array only to first wanted item and finish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iterateArrayToFirstResult(arr){ | |
loop: { | |
for (var i=0; i<arr.length; i++) { | |
if (arr[i]==42) { | |
console.log('You just found answer to the ultimate question of Life'); | |
break loop; | |
} | |
console.log('Your array havent number 42'); | |
} | |
} | |
} | |
iterateArrayToFirstResult([2,3,42,5,6]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment